You cannot have a conversation about design, without having a conversation about design notation UML, and object orientated analsysis, and design. UML is the prevailing notation used by SW programmers and BAs to model the problem domain. UML offers you groups of diagrams pretaining to
- Objects identification and messaging.
- Classification of objects into groups called classes
- Sequence and timing diagrams relationing to object interaction.
- Activity diagrams
- State transition diagrams.
So lets get into it!!! and start with the problem!!!
- Objects encapsulate data, only the public interface operations are available to a client.
- Changing an objects attributes, or reference values and you are changing its state. Change an objects state, could result in a change to the behaviour of the object.
- There are there types of objects to consider
- Entity : These classes map to you use cases, they are something know as application, or business objects. They also have data associated with them!! They are used by BAs to model the system.
- Boundary : Take input from the actor, and optional return results back to the actor. Look to the use case diagram to determine boundarys
- Controller : handles the execution sequence, captures the real world procedures we need to keep track of!!! The controller orchastes/mediates between entity and boundary classes. More over the controller recieves command from the boundary!! The controller implements one or more of your usecase!!!
- No matter how simple the system you will always have at least one boundary/control object. In some cases were simple is really simple, one class would serve as boundary, controller, where the controller is but an operation.
- The EBC pattern is a simpler representation of a MVC pattern.
- look to the flow of events in your use cases
- do text analysis noun-verb, nouns will represent objects, and verbs, operations. This is know as Abbots technique.
Example for using the Technique
- The customer enters the store to buy a toy.
- It has to be a toy that his daughter likes and it must cost less than 50 Euro.
- He tries a videogame, which uses a data glove and a head-mounted display. He likes it.
- An assistant helps him.
- The suitability of the game depends on the age of the child.
- His daughter is only 3 years old.
- The assistant recommends another type of toy, namely the boardgame “Monopoly".
Example |
Part of Speech |
Model Component |
"Monopoly” |
Proper noun |
object |
Toy |
Improper noun |
class |
Buy,recommend |
Doing verb |
operation |
is-a |
being verb |
inheritance |
has an |
having verb |
aggregation |
must be |
modal verb |
constraint |
Ref :
https://www1.in.tum.de/lehrstuhl_1/files/teaching/ws0607/Software%20Engineering%20I/L6_ObjectModeling.pdf
The idea for a class notation came into affect because of a need to classify groups of objects together!!! This grouping is a skill in its self, and will first lead to the classification name. Here are some pointers to classification.
Generating a Class Diagram from Flow of Events
Ref :
https://www1.in.tum.de/lehrstuhl_1/files/teaching/ws0607/Software%20Engineering%20I/L6_ObjectModeling.pdf
- Look to the objects that exist in the problem domain, you will see nouns i.e. names of persons, places or things. The Class names are usually that of nouns, but can identify processes too.
- A class will encapsulate the essence of the objects behaviour over a time period - observe your objects well to understand their full behaviour. The essence is notated via properties and operations which are specified in the class.
- A class can be instantiated.
- A class has methods, which is the code, which is the meat behind the operations of the class.
- The A-Class is an interest concept, remember classes are there to notate the object world.
- Abstract means empty - not reall, needs to be implementated!!!
- Consider the world of Pizza, you got a margertta, your peroni, your hawanina, and so on, they differ only with toppings. The base, and maybe the sauce too, is the same for our purposes. It makes sense to define the properties, and operations around a the family pizza objects into an abstract class, so that when a new pizza topping is invented, its still behaves like the old ones!!!
- Sometimes we want to boiler plate code that we know is common to all descendants that will make up the grouping.
- Note abstract classses are never instaniated!! they are used by overwriting there operations with method informaiton that is correct for they type of pizza!!! If you try to instantiate an abstract class you will get a runtime error.
- An abstract class contains properties and operations just like a real aka concrete class!!!.
- An abstract class will have abstract methods
Git Hub Source Code :
- Association is a relationship where all objects have their own lifecycle and there is no owner.
Eg :
Let's take an example of Teacher and Student. Multiple students can associate with single teacher and single student can associate with multiple teachers, but there is no ownership between the objects and both have their own lifecycle. Both can be created and deleted independently.
- Aggregation is a specialised form of Association where all objects have their own lifecycle, but there is ownership and child objects can not belong to another parent object.
Eg:
Let's take an example of Department and teacher. A single teacher can not belong to multiple departments, but if we delete the department, the teacher object will not be destroyed. We can think about it as a “has-a” relationship.
- Composition is again specialised form of Aggregation and we can call this as a “death” relationship. It is a strong type of Aggregation. Child object does not have its lifecycle and if parent object is deleted, all child objects will also be deleted.
Eg:
Let's take again an example of relationship between House and Rooms. House can contain multiple rooms - there is no independent life of room and any room can not belong to two different houses. If we delete the house - room will automatically be deleted.
Let's take another example relationship between Questions and Options. Single questions can have multiple options and option can not belong to multiple questions. If we delete the questions, options will automatically be deleted.
Eg : A Menu
The items on the menu could be listed as follows
Soup Of the Day
Steak n Chips
Apple Tart
A small menu indeed. The menu is an interface, it offers behaviour to the client. If the client has questions around the interface, he will as the waiter.
Consider the situation were you have multiple menus, as foods menu, a desserts menu, and a wine menu. This is an example of a restaurant, following the principle of interface segratation
As a coder, you should ensure that you class is not changed easyly, but this i mean that the flds of the class, should be set to private, and setters are not used, an object STATE should be set at construction. If not side effects are possible
- try not to use setters!!
- use constructors to set state!!
If you objects are mutable, then you will have have a thread safe program experience.
derived classes, are sub classes!!!
Course Notes
In our conversations on desing patterns we will use terms like
- Director
- Client
- Delegator
- x
- x
- Calling, calling framework
- Messaging
- Signalling
When trying to under a UML diagram, you need to ask question around the relationships, why they exist, and reference the objecst that the class if ultimately referenceing...
- This diagram, has handlers, and drivers.
- It expresses the events flow listed in a use case, or part of a use case.
- The Driver is the controller.
Note : The sequence diag. is the use case narrative, run through it, again and again, makeing sure both are in sync
- All objects have state, but are the worthy of a state diagram, yes, but only if they have at least three states, and are important to the business.
- A decision point will lead to a new state
- Use the state design pattern to enforce state in a classs.
Analysis
Q. What is the difference between an Interface and an Abstract class?
- You cannot instaniate an abstract class.
References
- http://www.cs.sjsu.edu/~pearce/modules/lectures/ooa/analysis/ecb.htm
- http://www.cs.sjsu.edu/~pearce/modules/lectures/ooa/analysis/browser/analysisModel.htm
- http://www.cs.sjsu.edu/~pearce/modules/lectures/ooa/analysis/atm/analysisModel.htm
- Be carefull, keep your dependencies under control!!!!
- Dependencies can be your downnfall!!!
- Choose your dependants well, are they right for you
App Servers
Test Frameworks
etc
- Dependency show be a one way street, you depend on them?