Class Design www.techstudent.co.cc Class Design The analysis phase determines what the implementation must do, and the system design phase determines the plan of attack. The purpose of class design is to complete the definitions of the classes and associations and choose algorithms for operations. The analysis model describes the information that the system must contain and the high-level operations that it mush perform. During design, you choose among different ways to realize the analysis classes with an eye toward minimizing execution time, memory, and other cost measures. In particular, you must flesh out operations choosing algorithms and breaking complex operations into simpler operations. www.techstudent.co.cc Class Design OO design is an iterative process. When you think that the class design is complete at one level of abstraction, you should consider the next lower level of abstraction. For each level you need to add new operations, attributes and classes. Class design involves the following steps. Bridging the Gap How to allocate available resources to the desired features. Your job is to build a bridge across the GAP. You must invent some intermediate elements to bridge the gap (operations, classes or other UML constructs). Inventing good intermediate elements is the essence of successful design. www.techstudent.co.cc Class Design www.techstudent.co.cc Class Design Realizing Use Cases During class design we elaborate the complex operations, most of which come from use cases. Use cases define system-level behavior. During design you must invent new operations and new objects that provide this behavior. Designing Algorithms. Formulate algorithm for each operations. The analysis specification tells what the operation does for its clients. Steps to design algorithms are as follows. www.techstudent.co.cc Class Design Choosing Algorithms that minimize the cost of implementing operations • Computational Complexity • Ease of implementation and understandability • Flexibility Select Data Structures appropriate to each algorithms Define new internal classes and operations necessary Decomposition of high-level operations. Usually you need to add internal operations as you expand high-level operations. Assign Operations to appropriate classes www.techstudent.co.cc Class Design Recursing Downward Organize operations as layers. Operations in the higher layers invoke operations in lower layers. The design process generally works top-down. Download recursion proceeds in tow ways: Functionality Layers. Functionality recursion means that you take the required high-level functionality and break it into lesser operations. This is a natural way to proceed. Mechanism Layers. This means you build the system out of layers of need support mechanisms. In providing functionality, you need various mechanisms to store information, www.techstudent.co.cc sequence control, coordinate objects, transmit Refactoring Class Design The changes to the internal structure of the software to improve its design without altering its external functionality. It may seem like a waste of time, but it is essential to main a design. Design Optimization A good way to design the system is to get the logic and then optimize it. It is difficult to optimize a design at the same time you create it. Design optimization involves the following paths. • Provide efficient access paths • Rearrange the computation for greater efficiency www.techstudent.co.cc • Save intermediate results to avoid recomputations Class Design Reification of Behavior It is the promotion of something that is not an object into an object. Adjustment of Inheritance As class design progresses, you can often adjust the definitions of classes and operations to increase inheritance by performing the following steps. • Rearrange classes and operations to increase inheritance • Abstract common behavior out of groups of classes • Use delegation to share behavior when inheritance is semantically invalid. www.techstudent.co.cc Class Design Organizing a Class Design It is possible to improve the organization of a class design with the following steps. • Hide Internal information from outside view Limit the scope of class-model traversals Do not directly access foreign attributes Define interfaces at a high level of abstraction Hide external objects avoid cascading method calls • Maintain coherence of entities • Fine-tune definition of packages www.techstudent.co.cc Implementation Modeling Implementation is the final development stage that addresses the specifics of programming languages. Implementation should be straightforward and almost mechanical, because you should made all the decisions during design. First you should address implementation issues called implementation modeling, which involves fine-tune classes, fine-tune associations, realize associations and prepare for testing. First two are motivated by the theory transformations. A transformation is a mapping from domain of models to the range of models. www.techstudent.co.cc Implementation Modeling Fine-tuning Classes Sometimes it is helpful to fine-tune classes before writing code in order to simplify development or to improve performance. The purpose of implementation is to realize the models from analysis and design. Do not alter design model unless there is a compelling reason. If there is, consider the following possibilities. Partition a class, Merge classes, Partition/Merge attributes or Promote an attribute/demote a class. Fine-tuning Generalizations As you can reconsider classes, so too you can reconsider generalizations. Sometimes it is helpful to remove a generalization or to add one prior to coding. www.techstudent.co.cc Implementation Modeling Realizing Associations Associations are the ‘glue’ of the class model, providing access paths between objects. Now we must formulate a strategy for implementing them. Either we can choose a global strategy for implementing all associations uniform, or we can select a particular technique for each associations, taking into account the way the application will use it. We to consider association classes, ordered associations, sequences, bags, qualified associations, aggregation and composition www.techstudent.co.cc Implementation Modeling Testing Testing is a quality assurance mechanism for catching residual errors. It provides an independent measure of the quality of your software. Testing should progress from small pieces to ultimately the entire application. Developers should begin by testing their own code, their classes and methods (Unit testing). Testing the fitness of classes and methods together (Integration testing). The final step is system testing, where you check the entire application. www.techstudent.co.cc www.techstudent.co.cc