Download presentation
Presentation is loading. Please wait.
Published byThomasina Terry Modified over 8 years ago
1
EC-241 Object-Oriented Programming LECTURE 9
2
Objectives: Introduction to Object Oriented Design Revise the basic principles of object orientation Unified Modeling Language (UML) Understand the basic concepts and terms of object orientation and associated UML notation
3
Object Orientation EncapsulationAbstraction Hierarchy Modularity Basic Principles of Object Orientation
4
Salesperson Not saying Which salesperson – just a salesperson in general!!! Customer Product Manages Complexity What is Abstraction?
5
Improves Resiliency What is Encapsulation? Hide implementation from clients – Clients depend on interface How does an object encapsulate? What does it encapsulate?
6
Order Processing System Billing Order Entry Order Fulfillment Manages Complexity What is Modularity? The breaking up of something complex into manageable pieces
7
Decreasing abstraction Increasing abstraction Elements at the same level of the hierarchy should be at the same level of abstraction Asset RealEstate Savings BankAccount Checking Stock Security Bond What is Hierarchy? Levels of abstraction
8
Introduction to Object Oriented Design Basic Principles of Object Orientation Unified Modeling Language (UML) Basic Concepts of Object Orientation
9
UML: Background OOA, OOD, and OOP Object-oriented methods may be applied to different phases in the software life-cycle e.g., Analysis, Design, implementation, etc. OO Analysis (OOA) is a process of discovery where a development team models and under-stands the requirements of the system OO Design (OOD) is a process of invention and adaptation where the development team creates the abstractions and mechanisms necessary to meet the system's behavioral requirements determined during analysis
10
UML: Modeling Modeling is a way of thinking about the problems using models organized around the real world ideas. A modeling method comprises a language and also a procedure for using the language to construct models. modeling is the only way to visualize your design and check it against requirements before your crew starts to code. References http://www.omg.org/gettingstarted/what_is_uml.htm http://www.inconcept.com/JCM/April1998/halpin.html
11
Unified Modeling Language (UML) The Unified Modeling Language (UML) is a standard language for Specifying Visualizing ConstructingDocumenting Business Modeling Communications
12
UML: Different Views Users (Use Case Diagrams) Designers (Class Diagrams) Analyzers (State Transition Diagrams)
13
UML: Different Views Analyzers (Sequence Diagrams) Analyzers (Activity Diagram)
14
Introduction to Object Oriented Design Basic Principles of Object Orientation Unified Modeling Language (UML) Basic Concepts of Object Orientation
15
Object Class Attribute (Data Member) Operation (Member Function) Relationships
16
Basic Concepts of Object Orientation Object Class Attribute Operation Relationships
17
Truck Chemical Process Linked List What is an Object? Informally, an object represents an entity, either physical, conceptual, or software – Physical entity – Conceptual entity – Software entity
18
A More Formal Definition An object is a concept, abstraction, or thing with sharp boundaries and meaning for an application An object is something that has: – State (values of data members) – Behavior (member functions) – Identity (name of object)
19
: Professor Professor Clark a + b = 10 ProfessorClark : Professor ProfessorClark Class Name Only Object Name Only Class and Object Name (stay tuned for classes) Representing Objects in UML An object is represented as rectangles with underlined names
20
Basic Concepts of Object Orientation Object Class Attribute Operation Relationships
21
OO Principle: Abstraction What is a Class? A class is a description of a group of objects with common properties (attributes or data members), behavior (operations or member functions), and relationships – An object is an instance of a class A class is an abstraction in that it: – Emphasizes relevant characteristics – Suppresses other characteristics
22
a + b = 10 Class Course Properties Name Location Days offered Credit hours Start time End time Behavior Add a student Delete a student Get course roster Determine if it is full Sample Class
23
Professor Professor Clark a + b = 10 Representing Classes in UML A class is represented using a compartmented rectangle
24
Professor name empID create( ) save( ) delete( ) change( ) Class Name Attributes Operations Class Compartments in UML A class is comprised of three sections – The first section contains the class name – The second section shows the structure (attributes or data members) – The third section shows the behavior (operations or member functions)
25
Objects Class Professor SmithProfessor JonesProfessor Mellon Professor The Relationship Between Classes and Objects A class is an abstract definition of an object – It defines the structure and behavior of each object in the class – It serves as a template for creating objects Objects are grouped into classes
26
Basic Concepts of Object Orientation Object Class Attribute Operation Relationships
27
:CourseOffering number = 101 startTime = 900 endTime = 1100 :CourseOffering number = 104 startTime = 1300 endTime = 1500 CourseOffering number startTime endTime Class Attribute Object Attribute Value What is an Attribute? In UML
28
Basic Concepts of Object Orientation Object Class Attribute Operation Relationships
29
CourseOffering addStudent deleteStudent getStartTime getEndTime Class Operation What is an Operation? In UML
30
Basic Concepts of Object Orientation Object Class Attribute Operation Relationships
31
UML Class Diagrams Name Attributes Operations Relations Associations Aggregation Generalization Class diagrams show the classes of the system, their interrelationships (including inheritance, aggregation, and association), and the operations and attributes of the classes. A class diagram is used to show the existence of classes and their relationships in the logical view of a system
32
UML Class Diagrams essentials Class Diagrams + Public - Private # protected Thier basic relation ships Association Aggregation generalization ClassName -operationt (): return type addStudent (): int + attribute : type + coursename : string
33
Relations Between Classes in UML Association -- a relationship between instances of the two classes. There is an association between two classes if an instance of one class must know about the other in order to perform its work. In a diagram, an association is a link connecting two classes. Aggregation (composition) -- an association in which one class belongs to a collection. An aggregation has a diamond end pointing to the part containing the whole. Generalization -- an inheritance link indicating one class is a superclass of the other. A generalization has a triangle pointing to the superclass.
34
Relationships: Association MultiplicitiesMeaning 0..1zero or one instance. The notation n.. m indicates n to m instances. 0..* or *no limit on the number of instances (including none). 1exactly one instance 1..*at least one instance
35
Relationships: Generalization A relationship among classes where one class shares the structure and/or behavior of one or more classes Defines a hierarchy of abstractions in which a subclass inherits from one or more superclasses – Single inheritance – Multiple inheritance Generalization is an “is-a-kind of” relationship
36
Account balance name number Withdraw() CreateStatement() Checking Withdraw() Savings GetInterest() Withdraw() Superclass (parent) Subclasses Generalization Relationship Ancestor Descendents Example: Single Inheritance in UML One class inherits from another
37
AirplaneHelicopterWolfHorse FlyingThingAnimal Bird multiple inheritance Use multiple inheritance only when needed, and always with caution ! Example: Multiple Inheritance in UML A class can inherit from several other classes
38
Use case diagrams are used to depict the context of the system to be built and the functionality provided by that system. They depict who (or what) interacts with the system. They show what the outside world wants the system to do. Essentials of Use case Diagram Actors, which represent users of a system, including human users and other systems. Use Cases, which represent functionality or services provided by a system to users. Use case diagrams
39
39 Example Use Case diagram Online shopping Actor Actor: An actor is a person, organization, or external system that plays a role in one or more interactions with your system Use case Use case: A use case describes a sequence of actions that provide something of measurable value to an actor and is drawn as a horizontal ellipse System boundary System boundary: indicates the scope of your system. Anything within the box represents functionality that is in scope and anything outside the box is not
40
Use case example
41
Sequence Diagrams describe interactions among classes. These interactions are modeled as exchange of messages. These diagrams focus on classes and the messages they exchange to accomplish some desired behavior. Sequence diagrams are a type of interaction diagrams. Sequence diagrams contain the following elements: Class roles, which represent roles that objects may play within the interaction. Lifelines, which represent the existence of an object over a period of time. (A dashed vertical line, called the lifeline, is drawn below each object.) Activations, which represent the time during which an object is performing an operation. Represented by rectangle Messages, which represent communication between objects. The notation used for messages (i.e., the line type and arrowhead type) indicates the type of message being used, Sequence Diagram
42
A sequence diagram is – An interaction diagram that details how operations are carried out. – What messages are sent and when. – Sequence diagrams are organized according to time
43
43 Example Sequence Diagram Object: Class Lifeline Operations Message
44
Activity Diagram Activity diagrams describe the workflow behaviour of a system Activity diagrams provide visual depictions of the flow of activities, whether in a system, business, workflow, or other process. Essentials of activity Diagrams: – Action nodes – Control nodes initial and final decision and merge fork and joint
45
45 Example Activity Diagram : processing an order. Start Fork Branch Merge Joint End
46
State Transition Diagram A State Transition diagram shows the possible states of the object and the transitions that cause a change in state. State machine diagrams are used to design and understand time-critical systems (real time processing) in which the consequences of improper timing are severe Essential – Initial final and simple states
47
47 Example State Transition Diagram for an Order object
48
Example State Transition Diagram
49
Example: Elevator Problem A product is to be installed to control elevators in a building with m floors. The problem concerns the logic required to move elevators between floors according to the following constraints: – Each elevator has a set of m buttons, one for each floor. These illuminate when pressed and cause the elevator to visit the corresponding floor. The illumination is cancelled when the elevator visits the corresponding floor. – Each floor, except the first floor and top floor has two buttons, one to request an up-elevator and one to request a down-elevator. These buttons illuminate when pressed. The illumination is cancelled when an elevator visits the floor and then moves in the desired direction. – When an elevator has no requests, it remains at its current floor with its doors closed.
50
Use case Diagram A generalized description of how a system will be used. Provides an overview of the intended functionality of the system. Understandable by laymen as well as professionals
52
Elevator basic scenario that can be extracted from Use Case Diagram: – Passenger pressed floor button – Elevator system detects floor button pressed – Elevator moves to the floor – Elevator doors open – Passenger gets in and presses elevator button – Elevator doors closes – Elevator moves to required floor – Elevator doors open – Passenger gets out – Elevator doors closes
53
Class Diagram Class diagrams show the static structure of the object, their internal structure, and their relationships.
54
Sequence Diagram Sequence Diagram for Serving Elevator Button
55
Sequence Diagram for Serving Door Button
56
Detail Class Diagram
57
Reference http://www.coderanch.com/how- to/content/uml-example.html http://www.coderanch.com/how- to/content/uml-example.html Recommended books – Object Oriented Analysis and Design with Application By Grady Booch, Third Edition (Chapter 5) – How to Program c++ By Dietel (our Text book)
58
Other Examples A simple digital watch has a display and two buttons to set it, the A button and the B button. Thewatch has two modes of operation, display time and set time. In the display time mode, hours andminutes are displayed, separated by a flashing colon. The set time mode has two modes, sethours and set minutes. The A button is used to select modes. Each time A is pressed, the modeadvances in sequence: display, set hours, set minutes, display etc. Within the sub modes, the Bbutton is used to advance the hours or minutes once each time it is pressed. Buttons must be released before they can generate another event. Prepare a state diagram of the watch. Simple Digital Watch
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.