chapter 5 class design. the deliverables of the class design process class diagrams are further...
TRANSCRIPT
![Page 1: Chapter 5 Class Design. The Deliverables of the Class Design Process Class diagrams are further refined in this phase of development Object diagrams are](https://reader033.vdocuments.net/reader033/viewer/2022051114/56649e915503460f94b971bb/html5/thumbnails/1.jpg)
Chapter 5
Class Design
![Page 2: Chapter 5 Class Design. The Deliverables of the Class Design Process Class diagrams are further refined in this phase of development Object diagrams are](https://reader033.vdocuments.net/reader033/viewer/2022051114/56649e915503460f94b971bb/html5/thumbnails/2.jpg)
The Deliverables of the Class Design Process
• Class diagrams are further refined in this phase of development
• Object diagrams are created
• Interaction diagrams are created
• Class skeletons are created to embody all analysis and design information created to this point in the development process
![Page 3: Chapter 5 Class Design. The Deliverables of the Class Design Process Class diagrams are further refined in this phase of development Object diagrams are](https://reader033.vdocuments.net/reader033/viewer/2022051114/56649e915503460f94b971bb/html5/thumbnails/3.jpg)
Class Skeletons
• We will preview class skeletons to better understand the objectives of design
• Class skeletons are partial class definitions • Class skeletons should be heavily commented,
so that the purpose of all attributes, methods, and constructors is clear
• Class skeletons are the basis for the implementation phase of development
![Page 4: Chapter 5 Class Design. The Deliverables of the Class Design Process Class diagrams are further refined in this phase of development Object diagrams are](https://reader033.vdocuments.net/reader033/viewer/2022051114/56649e915503460f94b971bb/html5/thumbnails/4.jpg)
Contents of Class Skeletons
• A list of the roles the class plays within the system• Information concerning when objects of the class
are created and deleted (information maintenance)• For each role, the semantics of the class• All attributes with access modifiers, types, names,
and semantics• For all constructors and methods, their signature,
semantics, preconditions and postconditions
![Page 5: Chapter 5 Class Design. The Deliverables of the Class Design Process Class diagrams are further refined in this phase of development Object diagrams are](https://reader033.vdocuments.net/reader033/viewer/2022051114/56649e915503460f94b971bb/html5/thumbnails/5.jpg)
LMS Class Skeleton
public class Patron{ // Class Semantics and roles // Library Patrons function in two primary // roles, as researchers who use index, // reference and database materials, and as // borrowers of loanable resources. // Information maintenance // Creation: new patrons are introduced // into the system by library staff when // presented with a library membership // application or from information // retrieved from a web-based application
![Page 6: Chapter 5 Class Design. The Deliverables of the Class Design Process Class diagrams are further refined in this phase of development Object diagrams are](https://reader033.vdocuments.net/reader033/viewer/2022051114/56649e915503460f94b971bb/html5/thumbnails/6.jpg)
More LMS Class Skeleton
// Information maintenance continued // Deletion: patrons are removed from the // library database 3 years after their // membership expires // // Instance variables private String name; // Patron name in // last, first, middle initial format private long PatronID; // Patron library ID // number. Automatically generated . . .( See deliverable 5.1 for other instance variables )
![Page 7: Chapter 5 Class Design. The Deliverables of the Class Design Process Class diagrams are further refined in this phase of development Object diagrams are](https://reader033.vdocuments.net/reader033/viewer/2022051114/56649e915503460f94b971bb/html5/thumbnails/7.jpg)
More LMS Class Skeleton
// Class variables private static long nextPatronID; // Keeps // track of next patronID to be assigned // Constructors public Patron(String n, long home, Date m, Date e, String street, String city, String state, long zip) { // Parameters: n = name, home = homephone // PatronID = getnextPatronID() // street,city, state, and zip are used // to create an address object for // homeAddress
![Page 8: Chapter 5 Class Design. The Deliverables of the Class Design Process Class diagrams are further refined in this phase of development Object diagrams are](https://reader033.vdocuments.net/reader033/viewer/2022051114/56649e915503460f94b971bb/html5/thumbnails/8.jpg)
More LMS Class Skeleton
// Constructors continued // Precondition: for constructor: // Library database can accept an // additional entry and memory allocation // succeeds // Postcondition: Library database will // contain an additional Patron and Address // entry } // Static methods public static long getnextPatronID() { return nextPatronID; nextPatronID++;}
![Page 9: Chapter 5 Class Design. The Deliverables of the Class Design Process Class diagrams are further refined in this phase of development Object diagrams are](https://reader033.vdocuments.net/reader033/viewer/2022051114/56649e915503460f94b971bb/html5/thumbnails/9.jpg)
More LMS Class Skeleton
// Non-static methods public boolean validatePatron(Date e) { // ensure membership is not expired // Precondition: expireDate != null // if expireDate <= Today return false // else return true } . . .( See deliverable 5.1 for other non-static methods )
} // end class Patron
![Page 10: Chapter 5 Class Design. The Deliverables of the Class Design Process Class diagrams are further refined in this phase of development Object diagrams are](https://reader033.vdocuments.net/reader033/viewer/2022051114/56649e915503460f94b971bb/html5/thumbnails/10.jpg)
System Decomposition
• Adds detail to the previous system representation
• Can be done iteratively or in a traditional, waterfall manner
• Each phase in the system development decomposes the system further
• Leads to a blueprint for implementation
![Page 11: Chapter 5 Class Design. The Deliverables of the Class Design Process Class diagrams are further refined in this phase of development Object diagrams are](https://reader033.vdocuments.net/reader033/viewer/2022051114/56649e915503460f94b971bb/html5/thumbnails/11.jpg)
More UML
• Access Modifiers + means public - means private # means protected
• Constraints (restriction on the class) { } E.g {Students may check out at most 25 items}
• Tagged values also use { } E.g. {Requirement #5}
![Page 12: Chapter 5 Class Design. The Deliverables of the Class Design Process Class diagrams are further refined in this phase of development Object diagrams are](https://reader033.vdocuments.net/reader033/viewer/2022051114/56649e915503460f94b971bb/html5/thumbnails/12.jpg)
More UML: Multiplicity
• Multiplicity or cardinality is represented above by the 0..1 and 0..*
• The above diagram indicates that a resource is checked out by 0 or 1 patrons and that each patron may check out 0 to many resources
Patron Resource0..1 checks out 0..*
![Page 13: Chapter 5 Class Design. The Deliverables of the Class Design Process Class diagrams are further refined in this phase of development Object diagrams are](https://reader033.vdocuments.net/reader033/viewer/2022051114/56649e915503460f94b971bb/html5/thumbnails/13.jpg)
More UML: Aggregation
Patron
Resource
• The solid diamond indicates that the Overdue form letter class consists of Patron and Resource objects
• The diamond is solid to indicate that the Patron and Resource classes exist in their own right
Overdueform letter
![Page 14: Chapter 5 Class Design. The Deliverables of the Class Design Process Class diagrams are further refined in this phase of development Object diagrams are](https://reader033.vdocuments.net/reader033/viewer/2022051114/56649e915503460f94b971bb/html5/thumbnails/14.jpg)
Interaction Diagrams
• Interaction diagrams model dynamic aspects of the system by specifying the interaction among objects to produce a particular behavior
• Two types of interaction diagrams are defined in UML– Collaboration diagrams, which emphasize the structural
organization of objects that send and receive messages
– Sequence diagrams, which emphasize the time ordering of the messages passed between objects
![Page 15: Chapter 5 Class Design. The Deliverables of the Class Design Process Class diagrams are further refined in this phase of development Object diagrams are](https://reader033.vdocuments.net/reader033/viewer/2022051114/56649e915503460f94b971bb/html5/thumbnails/15.jpg)
Notational Elements of Interaction Diagrams
Object Link Message
method(parameters)Object: class
• The object name is optional in the depiction of an object in UML notation
• An object is distinguished from a class in UML notation by the colon and underlining of the class name
![Page 16: Chapter 5 Class Design. The Deliverables of the Class Design Process Class diagrams are further refined in this phase of development Object diagrams are](https://reader033.vdocuments.net/reader033/viewer/2022051114/56649e915503460f94b971bb/html5/thumbnails/16.jpg)
LMS Case Study: Collaboration Diagram(Partial)
: Patron
: Library System
: LibraryDatabase
Checkout(R
esource
ID)
validate
Patron(M
emDate
)
( See deliverable 5.3 for entire diagram )
update(Patron)
create(LibraryDatabase)
getResource(ResourceID)
getPatron(PatronID)
![Page 17: Chapter 5 Class Design. The Deliverables of the Class Design Process Class diagrams are further refined in this phase of development Object diagrams are](https://reader033.vdocuments.net/reader033/viewer/2022051114/56649e915503460f94b971bb/html5/thumbnails/17.jpg)
Steps for Creating Collaboration Diagrams
• Identify a behavior to model
• Identify participating class and their relevant interrelationships
• Identify a specific scenario to model
• determine necessary message passing to carry out the behavior
• Introduce solution for object persistence, if needed
![Page 18: Chapter 5 Class Design. The Deliverables of the Class Design Process Class diagrams are further refined in this phase of development Object diagrams are](https://reader033.vdocuments.net/reader033/viewer/2022051114/56649e915503460f94b971bb/html5/thumbnails/18.jpg)
Sequence Diagrams
• Like collaboration diagrams, sequence diagrams model dynamic aspects of the system by specifying the interaction among objects to produce a particular behavior
• Sequence diagrams specify the time ordering of messages
• Sequence diagrams show the life span of each object
![Page 19: Chapter 5 Class Design. The Deliverables of the Class Design Process Class diagrams are further refined in this phase of development Object diagrams are](https://reader033.vdocuments.net/reader033/viewer/2022051114/56649e915503460f94b971bb/html5/thumbnails/19.jpg)
LMS Case Study: Sequence Diagram(Partial)
: Patron : Library System : LibraryDatabase
create(LibraryDatabase)
getResource(ResourceID)
getPatron(PatronID)
validatePatron(MemDate)
(See deliverable 5.5 for entire diagram )
![Page 20: Chapter 5 Class Design. The Deliverables of the Class Design Process Class diagrams are further refined in this phase of development Object diagrams are](https://reader033.vdocuments.net/reader033/viewer/2022051114/56649e915503460f94b971bb/html5/thumbnails/20.jpg)
Evaluating Design
• Modeling software helps us produce correct, well- structured systems
• The resultant models can also be scrutinized for potential data integrity problems
• For example, in the LMS system, having update methods execute separately for the Patron and Resource objects may result in data integrity errors if system failure occurs between the initiation of the first method and the termination of the second method
![Page 21: Chapter 5 Class Design. The Deliverables of the Class Design Process Class diagrams are further refined in this phase of development Object diagrams are](https://reader033.vdocuments.net/reader033/viewer/2022051114/56649e915503460f94b971bb/html5/thumbnails/21.jpg)
Object Diagrams
• Models a set of objects and their interrelationships during a system snapshot
• A system snapshot is the state of the software system at a selected moment of time
• Object diagrams model another static perspective of the system
• Unlike other diagrams, object diagrams may contain multiple instances of the same class
![Page 22: Chapter 5 Class Design. The Deliverables of the Class Design Process Class diagrams are further refined in this phase of development Object diagrams are](https://reader033.vdocuments.net/reader033/viewer/2022051114/56649e915503460f94b971bb/html5/thumbnails/22.jpg)
LMS Case Study: Object Diagram (partial)
currentP: Student : Listname=“Gert Stein”libraryID=6747632homephone=5554321workphone=5551234membership=05011999expire=05012002
:Bookname = “SOTY”author=“b. hooks”ISBN= ...
:Bookname = “FOF”author=“Ehrenreich”ISBN= ...
(See deliverable 5.7 for entire diagram )
![Page 23: Chapter 5 Class Design. The Deliverables of the Class Design Process Class diagrams are further refined in this phase of development Object diagrams are](https://reader033.vdocuments.net/reader033/viewer/2022051114/56649e915503460f94b971bb/html5/thumbnails/23.jpg)
Steps for Creating Object Diagrams
• Identify a system snapshot within a scenario to model
• Identify participating classes and their interrelationships
• Identify all allocated objects at the time of the snapshot
• Show the state of each object in the snapshot
• Determine all interobject links
![Page 24: Chapter 5 Class Design. The Deliverables of the Class Design Process Class diagrams are further refined in this phase of development Object diagrams are](https://reader033.vdocuments.net/reader033/viewer/2022051114/56649e915503460f94b971bb/html5/thumbnails/24.jpg)
Code Reuse
• Collaboration diagrams are of particular use in pattern scavenging
• Pattern scavenging involves studying the various diagrams produced during analysis and class design to identify patterns of class interaction
• Once such patterns are found, they should be evaluated to determine if they can be effectively reused
![Page 25: Chapter 5 Class Design. The Deliverables of the Class Design Process Class diagrams are further refined in this phase of development Object diagrams are](https://reader033.vdocuments.net/reader033/viewer/2022051114/56649e915503460f94b971bb/html5/thumbnails/25.jpg)
Reuse in LMS
Resource
CheckableResource
ReserveResource
Book Electronic
Media
![Page 26: Chapter 5 Class Design. The Deliverables of the Class Design Process Class diagrams are further refined in this phase of development Object diagrams are](https://reader033.vdocuments.net/reader033/viewer/2022051114/56649e915503460f94b971bb/html5/thumbnails/26.jpg)
Guidelines for Class Design
• Always keep data private• Always initialize data in a constructor• Do not use too many related primitives• Not all attributes need individual accessor or mutator
methods• Order elements comprising class definitions
consistently• Break up overly complex classes into multiple
classes• Name classes, methods and attributes well
![Page 27: Chapter 5 Class Design. The Deliverables of the Class Design Process Class diagrams are further refined in this phase of development Object diagrams are](https://reader033.vdocuments.net/reader033/viewer/2022051114/56649e915503460f94b971bb/html5/thumbnails/27.jpg)
Verification of the Class Design
• All system requirements developed during analysis must be addressed during design– All design documents must cross reference requirements
from the requirements specification
• All required attributes and methods must be used properly– E.g. data integrity of attributes must be enforced by
update methods
• The modules comprising the system must work together properly