Download presentation
Presentation is loading. Please wait.
Published byJocelyn Eaton Modified over 9 years ago
1
Class diagram refactoring example P3 practical example T120B029 2012 pavasario semestras
2
Typical e-commerce example The code that retrieves all products within a given category and store results in a cash.
3
3 The Snowflake Rule The Snowflake Rule – For a non- trivial system, no two analysts will come up with the identical class models for the same application domain T120B029
4
Atributes and methods Determining classes is an iterative task! How do we name attributes? Meaningful in a business context e – eilutė, i – indeksas ;-)
5
Modeling Associations UML has several relations that seem to all mean the same thing : "has a". 1.Association, 2.Aggregation, 3.Composition So, what is the difference between them?
6
Association Represents the ability of one instance to send a message to another instance. Implemented as a local variable (pointer) or as a method. The arrowheads on the end of the line indicate the directionality of the association
7
Association example
8
Aggregation Sometimes an object is made up of other objects. A part cannot contain its whole. makes sense - a room is part of a building doesn't make sense - an address is part of a person
9
Composition Particular case of aggregation The room can not exist without building
10
Generalization “is-a” relationship
11
Realization the relationship between the interface and the implementing class
12
Dependancy Connect two classes to indicate that the connection between them is at a higher level of abstraction than an association relationship A change to the Product class might require a change to the Cart class
13
Refactoring: what‘s wrong with our example?
14
Wrong things are 1.The ProductService depends on API changes of the ProductRepository. 2.The code is untestable. Without having a real ProductRepository unable to test ProductService. 3.Dependancy on HttpContext as a cache storage provider (platform specific!)
15
Dependancy inversion principle Decouple ProductService from ProductRepository by having both depend from an interface
16
Dependancy injection principle Move the responsibility of creating ProductRepository implementation out of the ProductService class
17
Dependancy injection for cache Fine, but problem remains: HttpContect API can’t implement the new ICacheStorage interface
18
Adapter Pattern
19
The result of application of the adapter pattern
20
Special case What if you don’t want to cache data? Problem: always provide the ProductService constructor with the implementation of IChacheStorage Provide a null reference and littering the code with checks for a null
21
Null Object (Spesial case) pattern Public class NullObjectCache : ICacheStorage{ public void Store(){ //Do nothing }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.