Modeling Classes with UML CSCE 121 Modeling Objects

Modeling Classes with UML CSCE 121

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 vector 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

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 • <Attribute. Name>: <Attribute. Type> • 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 checked. Out. By: Patron

Methods Book • <Method. Name>(<parameter>: <Attribute. Type>): <Return. Type> • Start with lowercase title: String author: String due: Date check. Out(patron: Patron, due: Date) get. Author(): String set. Title(title: String)

Visibility Book • Public: prepend name with ‘+’ • Private: prepend name with ‘-’ -title -author: String -due: Date +check. Out(patron: Patron, due: Date) +get. Author(): String +set. Title(title: String)

Relationships • Show relationship between classes • Association • Has a • Aggregation • Has an aggregation (grouping) of • Composition • Like has a, but is a part of • More later… Person Class Roster Person Umbrella Student Arm

Library Relationships -name: String -collection: Book +add. Book(book: Book) -title: String -author: String -due: Date -check. Out. By: Patron +check. Out(patron: Patron, due: Date) +get. Author(): String +set. Title(title: String) Try to m atch re lation t attribut o e/meth od or to th e name. Patron -name: String
- Slides: 10