UML: CLASS DIAGRAMS Intended learning outcomes Define structural (static) models Implement modelling methodology Identify and use standard UML notation for structural modelling Create simple class diagrams Identify opportunities for refinement Where we are… Develop System Request Understand As-Is system Identify improvement opportunities Develop the To-Be system concept Develop Use Cases Develop Structural Model The Class Diagram STRUCTURAL MODELING Key Ideas A structural (static) or conceptual model describes the structure of the data that supports the business processes in an organization. The structure of data used in the system is represented through CRC cards, class diagrams, and object diagrams. Elements of a CRC card Front: Class name: Description: Responsibilities: Collaborators: Back: Attributes: Relationships: Generalization (a-kind-of): Aggregation (has-parts): Other Associations: STRUCTURAL MODELS Purpose of Structural Models Reduce the “semantic gap” between the real world and the world of software Create a vocabulary for analysts and users Represent things, ideas, and concepts of importance in the application domain Classes Templates for creating instances or objects Concrete Abstract Typical examples: Application domain, user interface, data structure, file structure, operating environment, document, and multimedia classes Attributes Units of information relevant to the description of the class Only attributes important to the task should be included Operations Action that instances/objects can take Focus on relevant problem-specific operations (at this point) Relationships Generalization Enables inheritance of attributes and operations Aggregation Relates parts to wholes Association Miscellaneous relationships between classes CLASS DIAGRAMS Example Class Diagram Class Diagram Syntax A CLASS Class1 -attribute +operation () AN ATTRIBUTE attributeName /derivedAttributeName AN OPERATION operationName () AN ASSOCIATION 1..* 0..1 ______verb phrase____ The Class Diagram Use of Natural Language Discard inappropriate candidates From the nouns in the problem statement Eliminate the redundant irrelevant - those unrelated to the problem Vague - ill-defined boundary, very broad in scope attributes - things that describe an object operations - things that manipulate objects implementation constructs - extraneous to real world must be eliminated from analysis model, needed during design, but not now. Example: problem statement for library automation system Design the software to support the operation of a public library. The system has a number of stations and PCs for customer transactions. These stations are operated by library employees. When a book is borrowed, the identification card of the client is read. Next, the station’s barcode reader reads the book’s code. When a book is returned, the identification card is not needed and only the book’s code needs to be read. Object modelling – identifying classes Library automation system – potential object list Object modelling – keeping the right classes Object Elimination reason Object Modeling - The Good Classes Object modelling – data dictionary Prepare a data dictionary/ description of each class Station – a terminal linked to a central computer operated by employees with a barcode reader. Identify Associations Associations correspond to verbs in the problem statement Association = any dependency between two classes From the problem statement Employee operates station From tacit knowledge Library owns computer Initial class diagram Further Specify the semantics of associations Include Multiplicity Qualifier or Qualified Associations Usually a name identifies an object within some context; most names are not globally unique. The context combines with the name to uniquely identify the object. A Qualifier distinguishes objects on the many side of an association. For example, a qualifier bankcode could be added to distinguish the different banks in a consortium. Each cash card needs a bank code so that transactions can be directed to the appropriate bank. Identifying Attributes and operations Attributes Properties of an individual object Usually possessive phrases e.g. the colour of the car Identify from the problem description and domain knowledge Operations Define ways in which objects interact Identifying attributes This class diagram could be refined with inheritance - can you identify where ? Developing Structural Models - Summary Identify the main Use-cases and write down descriptions of these Identify the main elements of information which must be stored. Identify the main actors with which the system must interact. Identify objects and classes Identify associations between classes Creating object model segments for each Use-case. Identify attributes for classes Merge the object model segments to create an overall object model for the system Organise and simplify classes using inheritance Test the object model and its relationships by performing walk-through using, for example, UML Sequence diagrams (Dynamic Modeling) Iterate and refine the models Summary Class and object diagrams show the underlying structure of an object-oriented system. Constructing the structural model is an iterative process involving: textual analysis, brainstorming objects, role playing, creating the diagrams, and incorporating useful patterns.