100 likes | 203 Vues
This chapter explores the principles of object design in software development, focusing on use case realization, command-query separation, and the interaction between UI and domain objects. It discusses foundational design patterns such as Creator, Information Expert, and Controller, highlighting their importance in achieving low coupling and high cohesion. Example scenarios, such as the creation of sales in a point-of-sale system, illustrate how to implement these concepts in practice, empowering developers to construct robust and maintainable software architectures.
E N D
Chapter 18 Object Design Examples with GRASP CS6359 Fall 2011 John Cole
Use Case Realization • Describes how a particular use case is realized within the design model in terms of collaborating objects CS6359 Fall 2011 John Cole
Command-Query Separation • A method that changes the value of a variable (or the state of the object) should not also return (query) its value. • A method that returns the value of a variable should not also change it. CS6359 Fall 2011 John Cole
Connect UI to Domain • An initializer object creates both the UI and the domain objects and passes the domain object to the UI • The UI object retrieves the domain object from a well-known source such as a factory object that creates domain objects CS6359 Fall 2011 John Cole
Basic Patterns • Creator • Information Expert • Controller • Low Coupling • High Cohesion CS6359 Fall 2011 John Cole
Realization • Look at the objects suggested by the use case • Determine who should create them • Decide how they should interact • Determine which patterns are being used. CS6359 Fall 2011 John Cole
Example: Sell Something • Register could create the Sale object • Sale object creates SalesLineItem objects in list • SalesLineItem interacts with Product to get pricing and description CS6359 Fall 2011 John Cole
Design makeNewSale • Register creates Sale instance s and stores the reference • Attributes of s are initialized CS6359 Fall 2011 John Cole
Controller Class Design • Represents the overall system or “root object” • “Store” in the POS system is a root object because other objects exist within it • POSSystem is also a root object • Register could also be a root object CS6359 Fall 2012 John Cole
Creating a New Sale • Register creates a Sale object • Sale object, as part of its initialization, creates an empty list of SalesLineItems • Register is, therefore, the Controller CS6359 Fall 2011 John Cole