Modeling Classes with UML CSCE 121 J. Michael Moore
Modeling Objects Objects used in many programming languages Ideally is independent of the programming language Language Agnostic The focus should be what instead of how. There are many options, so leave the implementation details to the coder. Think about what data means or a mathematical definition instead of focusing on the datatypes available in a language. Dollars instead of double. Integer instead of int. Floating point instead of double or float. Letters instead of char. List instead of vector. (You can say array if you mean it in the mathematical sense.)
Class Start thinking about what you want to represent Characteristics Candidates for attributes Actions (by / to object) Candidates for methods
UML Unified Modeling Language Used primarily for Software Engineering Language Agnostic Many types of UML diagrams used for design and modeling Class diagrams Structure diagrams Sequence diagrams Activity diagrams State machine diagrams
Methods / Member Functions UML Class Diagram Model Classes (language agnostic of course!) 3 parts Include what we need, not everything we can think of. Programs can help Visio: Free on Dreamspark http://creately.com/ (Collaborative) Any program you can draw boxes and type text! Name Attributes / Data Members Methods / Member Functions
Attributes Book <AttributeName>: <AttributeType> Attribute Type is optional Start with lowercase Type after colon Types are NOT C++ datatypes! Should be descriptive of what it is, not how it will be stored in C++ Ex: Dollars instead of double Can include this type of information for methods too Book title author: String due: Date checkedOutBy: Patron
Methods <MethodName>(<parameter>: <AttributeType>):<ReturnType> Start with lowercase Book title: String author: String due: Date checkOut(patron: Patron, due: Date) getAuthor(): String setTitle(title: String)
Visibility Book Public: prepend name with ‘+’ Private: prepend name with ‘-’ Book -title -author: String -due: Date +checkOut(patron: Patron, due: Date) +getAuthor(): String +setTitle(title: String)
Relationships Show relationship between classes Association Person Has a Aggregation Has an aggregation (grouping) of Composition Like has a, but is a part of More later… Person Umbrella Class Roster Student Person Arm
Try to match relation to attribute/method or to the name. Relationships Library -name: String -collection: Book Book +addBook(book: Book) -title: String -author: String -due: Date -checkOutBy: Patron Patron +checkOut(patron: Patron, due: Date) +getAuthor(): String +setTitle(title: String) Try to match relation to attribute/method or to the name. -name: String