Sunday, March 24, 2013

Identifying Classes using modelling

Identifying the right classes for a System is an Art rather than a skill.Modelling too many classes results in too complex code which is difficult to maintain and may also result in poor performance.On the other hand if there are too few classes then it may result in tight coupling.Striking a balance between these provides the basis for a good design.
When designing a system,always believe that the best design is yet to come.Revisiting and Refining the proposed design will always aid to carve out the best design.The domain knowledge is essential key factor to come up with a good design.
Since it may not be feasible for a Designer to be a domain expert right from the begining ,there are some design guidelines to identify the classes.The most commonly used approaches are
1.Noun/Noun Pharses approach:
In this approach ,all the noun and noun phrases are identified from the requirements.
2. CRC card approach:
Using the Class Responsibility Collaborator approach,address a single requirement ,identify the similar objects and group them into a class .Add the responsibility and collaborations for this class.Extending the same to each requirement will render a list of Candidate classes.
Using these approaches,the list of candidate classes can be identified.From the list remove the classes which are duplicate and those which are not related to the system.On analysing the classes,if you find that the class does have significant purpose then define it as an attibute instead of a class .At the end of this analysis a number of candidate classes would be eliminated and the design classes would be derived from this list.
As the design progresses its very common to find that a few of the classes which were identified as the core classes may not be actually required .Having said that it is also possible to come up with totally new classes which were missed in the initial candidate class.
The right set of classes would eventually emerge after a number of interative and incremental cycles.