CSC441 Intro to SE: Introduction to UML, OO Modelling & Class Diagrams PDF

Summary

This document is a lecture on Introduction to UML, OO Modelling, and Class Diagrams, intended for a Software Engineering course. It provides an overview of concepts like classes, objects, attributes, and operations as part of object-oriented software design and modelling. The lecture includes a discussion on topics such as modelling, UML diagrams, and tools in the field.

Full Transcript

(CS251) Lecture 4 Introduction to UML, OO SOFTWARE ENGINEERING 1 Modelling, & Class Diagrams Dr. Amr S. Ghoneim INTRODUCTION TO UML, OO MODELLING, & CLASS DIAG...

(CS251) Lecture 4 Introduction to UML, OO SOFTWARE ENGINEERING 1 Modelling, & Class Diagrams Dr. Amr S. Ghoneim INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 1 o Classes and Objects o Classification TOPICS COVERED o Abstraction o Encapsulation o Inheritance o Modelling o How to use Inheritance? o Some UML Diagrams o Polymorphism o UML Tools o Generics o Static Diagrams o Class Model o Class Model o Objects o Values and Attributes o What is OO Software? o Operations and Methods o Object Oriented “OO” Characteristics o Summary of Basic Class Notation o Identity o Sample Class Model INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 2 THE SOFTWARE PROCESS A structured set of activities required to develop a software system. Many different software processes but all involve:  Specification – defining what the system should do;  Design and implementation (Development) – defining the organization of the system and implementing the system;  Validation (Testing) – checking that it does what the customer wants;  Maintenance & Evolution – changing the system in response to changing customer needs. A software process model is an abstract representation of a process. It presents a description of a process from some particular perspective. INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 3 MODELLING A model is an abstraction of a system. Abstraction allows us to ignore unessential details Why building models?  To reduce complexity  To test the system before building it  To communicate with the customer  To document and visualize your ideas INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 4 SOME UML DIAGRAMS Functional diagrams  Describe the functionality of the system from the user’s point of view. It describes the interactions between the user and the system. It includes use case diagrams. Static diagrams  Describe the static structure of the system: Classes, Objects, attributes, associations. Dynamic diagrams:  Interaction diagrams  Describe the interaction between objects of the system  State diagrams  Describe the temporal or behavioral aspect of an individual object  Activity diagrams  Describe the dynamic behavior of a system, in particular the workflow. INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 5 UML TOOLS Some UML tools can generate code once UML diagram is completed. Some UML tools are sketching tools. Rational Rose is one of the most popular software for UML creation (IBM). Bouml is an open source s/w. It supports python, C++, java. Visio is a sketching tool. INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 6 STATIC DIAGRAMS Class diagrams: show the classes and their relations. Object diagrams: show objects and their relations. Package diagrams: show how the various classes are grouped into packages to simplify complex class diagrams. INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 7 CLASS MODEL A class model captures the static structure of the system by characterizing  the classes and objects in the system,  the relationships among the objects and  the attributes and operations for each class of objects Class models are the most important OO models. In OO systems we build the system around objects not functionality. INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 8 WHAT IS OO SOFTWARE? Object-oriented software means that we organize software as a collection of discrete objects that incorporate both data structure and behavior. The fundamental unit is the Object. An object has state (data) and behavior (operations). In Structured programming, data and operations on the data were separated or loosely related. INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 9 OBJECT ORIENTED “OO” CHARACTERISTICS Identity Classification Encapsulation Abstraction Inheritance Polymorphism Generics Cohesion Coupling INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 10 IDENTITY An object can be concrete like a car, a file, … An object can be conceptual like a feeling, a plan,… Each object has its own identity even if two objects have exactly the same state. Omar’s car Rana’s car INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 11 IDENTITY Object identity is the property by which each object can be identified and treated as a distinct software entity. Each object has unique identity which distinguishes it from all its fellow objects. It is its memory address (or handle) that is referred to by one or more object identifiers (variables). INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 12 IDENTITY car my_car = new car(“Opel”, 2005); The object handle is 0x00FDA610 is referenced by an object identifier (object variable) my_car 0x00FDA610 model: Opel year: 2005 my_car 0x00FDA610 INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 13 CLASSES AND OBJECTS 14 Each object is an instance of a class INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS Each object has a reference to its class (knows which class it belongs to) CLASSIFICATION Classification means that objects with the same data structure (attributes) and behavior (operations) belong to the same class. A class is an abstraction that describes the properties important for an application The choice of classes is arbitrary and application-dependent. 3 2 Mina’s car Ali’s car Samir’s car A Car INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 15 CLASSIFICATION Objects in a class share a common semantic purpose in the system model. Both car and cow have price and age. If both were modeled as pure financial assets, they both can belong to the same class. If the application needs to consider that:  Cow eats and produces milk  Car has speed, make, manufacturer, etc. then model them using separate classes. So the semantics depends on the application INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 16 ABSTRACTION Abstraction is the selective examination of certain aspects of a problem. Abstraction aims to isolate the aspects that are important for some purpose and suppress the unimportant aspects. The purpose of abstraction determines what is important and what is not. INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 17 ABSTRACTION Car Car -model: string -model: string -Year: string -year: int -problem: string -licenseNumber: string -owner: string -motorCapacity: int -balance: float -isFinished: bool +Car (int, ….): void +Car (string,...): void +getMake (): string +printBlanace (): string +printDetails(): void +printDetails(): void +........ +........ In Department of At the Motor Vehicles mechanic INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 18 ENCAPSULATION Encapsulation separates the external aspects of an object, that are accessible to other objects, from the internal implementation details that are hidden from other objects. Encapsulation reduces interdependency between different parts of the program. You can change the implementation of a class (to enhance performance, fix bugs, etc) without affecting the applications that use objects of this class. INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 19 ENCAPSULATION Data hiding. information from within the object cannot be seen outside the object. Implementation hiding. implementation details within the object cannot be seen from the outside. INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 20 ENCAPSULATION void sort () { // Bubble Sort int i, j; for (i = length - 1; i > 0; i-) { List for (j = 0; j < i; j++) { - items: int [ ] if (items [j] > items [j + 1]) { - length: int int temp = items [j]; items [j] = items [j + 1]; + List (array): void items [j + 1] = temp; + search (int): bool } + getMax (): int } + sort(): void } }` void sort () { // Quick Sort ………. }` INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 21 INHERITANCE Inheritance is the sharing of features (attributes and operations) among classes based on a hierarchical relationship. A superclass (also parent or base ) has general features that sublcasses (child or derived ) inherit. and may refine some of them. Inheritance is one of the strongest features of OO technology. INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 22 INHERITANCE Inheritance is the facility by which objects of a class (say B) may use the methods and variables that are defined only to objects of anotherAclass (say A), as if these methods and variables have been defined in class B Inheritance is represented as B shown in UML notation. INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 23 HOW TO USE INHERITANCE? Car Inheritance helps building software -motorCapacity: int incrementally: -model: string -make: string First; build classes to cope with the -year: int most straightforward (or general) case, +Car (int, ….): void +getMake (): string Second; build the special cases that +printDetails(): void inherit from the general base class. +........ These new classes will have the same features of the base class plus their own. Taxi Truck INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 24 POLYMORPHISM Polymorphism means that the same operation may behave differently for different classes. An operation is a procedure or a transformation that the object performs or is subject to. An implementation of an operation by a specific class is called a method. Because an OO operation is polymorphic, it may have more than one method for implementing it, each for a different class. INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 25 POLYMORPHISM Shape Italic means - color: int operation is specified but not + Shape (int): void implemented in + getColor (): int the base class + setColor (int): void + getArea(): float Rectangle Circle Square - length: float - radius: float - side: float - width: float + Circle(int, int): void + Square(int, int): void + Rectangle ……. + getRadius(): float + getSide(): float + getArea(): float + setRadius(): float + setSide(): float + getArea(): float + getArea(): float length x width side2 x radius2 INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 26 GENERICS Generic Class ; the data types of one or more of its attributes are supplied at run-time (at the time that an object of the class is instantiated). This means that the class is parameterized, i.e., the class gets a parameter which is the name of another type. T will be known Sorter at runtime.. - data [ ]: T + sortData (): void + ……. INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 27 CLASS MODEL A class model captures the static structure of the system by characterizing  the classes and objects in the system,  the relationships among the objects and  the attributes and operations for each class of objects Class models are the most important OO models In OO systems we build the system around objects not functionality INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 28 OBJECTS Objects often appear as proper nouns in the problem description or discussion with the customer. Some object correspond to real world entities (BUE, MIT, Omar’s car) Some objects correspond to conceptual entities (the formula for solving an equation, binary tree, etc.) The choice of objects depends on the analyst’s judgment and the problem in hand. There can be more than one correct representation. INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 29 CLASS An object is an instance of a class A class describes a group of objects with the same  Properties (attributes)  Behavior (operations)  Kinds of relationships Person, Company and Window are all classes Classes often appear as common nouns and noun phrases in problem description and discussion with customers or users INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 30 CLASS MODEL Provides a graphical notation for modeling classes and their relationships, thereby describing possible objects. Class diagram is useful for:  Designing and Implementing the programs. INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 31 VALUES AND ATTRIBUTES An attribute is a named property of class that describes a value held by each object of that class. Attribute name is unique per class. Several classes may have the same attribute name. A value is a piece of data assigned to an attribute. INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 32 MORE ON ATTRIBUTES INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 33 OPERATIONS AND METHODS An operation is a function or procedure that may be applied to or by objects Financial Asset of a class. -type: int -age: float A method is the implementation of an -currentValue: float operation for a class. -... An operation is polymorphic if it takes +getCurrentValue(): int different forms in different classes. +printDetails(): void +........ All objects of the same class have the same operations. INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 34 SUMMARY OF CLASS NOTATION The attribute and operation compartments are optional. You may show them or not depending on the level of abstraction you want. A missing attribute compartments means that the attributes are not specified yet. But empty compartment means that the attributes are specified but there are none. INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 35 SUMMARY OF BASIC CLASS NOTATION INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 36 36 A SAMPLE CLASS MODEL Model the classes in a system that represents flights. Each city has at least an airport. Airlines operate flights from and to various airports. A flight has a list of passengers, each with a designated seat. Also a flight uses one of the planes owned by the operating airline. Finally a flight is run by a pilot and a co-pilot. INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 37 A SAMPLE CLASS MODEL Model the classes in a system that represents flights. Each city has at least an airport. Airlines operate flights from and to various airports. A flight has a list of passengers, each with a designated seat. Also a flight uses one of the planes owned by the operating airline. Finally a flight is run by a pilot and a co-pilot. INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 38 A SAMPLE CLASS MODEL Flights City Airlines List of Passengers Seat Planes Pilot and a Co-Pilot City Airline Pilot Plane Passenger Airport Flight Seat INTRODUCTION TO UML, OO MODELLING, & CLASS DIAGRAMS 39 THANKS!.. QUESTIONS? 40

Use Quizgecko on...
Browser
Browser