600 likes | 803 Views
EC-241 Object-Oriented Programming. LECTURE 9. 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. Object Orientation.
E N D
EC-241 Object-Oriented Programming LECTURE 9
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
Object Orientation Abstraction Encapsulation Modularity Hierarchy Basic Principles of Object Orientation
Salesperson Not saying Which salesperson – just a salesperson in general!!! Product Customer What is Abstraction? Manages Complexity
What is Encapsulation? • Hide implementation from clients • Clients depend on interface How does an object encapsulate? What does it encapsulate? Improves Resiliency
What is Modularity? • The breaking up of something complex into manageable pieces Order Entry Order Processing System Order Fulfillment Billing Manages Complexity
Increasing abstraction Decreasing abstraction What is Hierarchy? Asset • Levels of abstraction Security RealEstate BankAccount Savings Checking Stock Bond Elements at the same level of the hierarchy should be at the same level of abstraction
Introduction to Object Oriented Design • Basic Principles of Object Orientation • Unified Modeling Language (UML) • Basic Concepts of Object Orientation
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
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.htmhttp://www.inconcept.com/JCM/April1998/halpin.html
Specifying Unified Modeling Language (UML) The Unified Modeling Language (UML) is a standard language for Constructing Documenting Visualizing Communications Business Modeling
UML: Different Views Users (Use Case Diagrams) Designers (Class Diagrams) Analyzers (State Transition Diagrams)
UML: Different Views Analyzers (Activity Diagram) Analyzers (Sequence Diagrams)
Introduction to Object Oriented Design • Basic Principles of Object Orientation • Unified Modeling Language (UML) • Basic Concepts of Object Orientation
Basic Concepts of Object Orientation • Object • Class • Attribute (Data Member) • Operation (Member Function) • Relationships
Basic Concepts of Object Orientation • Object • Class • Attribute • Operation • Relationships
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
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)
Professor Clark Representing Objects in UML • An object is represented as rectangles with underlined names : Professor a + b = 10 ProfessorClark Class Name Only ProfessorClark : Professor Object Name Only Class and Object Name (stay tuned for classes)
Basic Concepts of Object Orientation • Object • Class • Attribute • Operation • Relationships
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 OO Principle: Abstraction
Sample Class 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 a + b = 10
Representing Classes in UML • A class is represented using a compartmented rectangle a + b = 10 Professor Professor Clark
Class Name Professor name Attributes empID Operations create( ) save( ) delete( ) change( ) 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)
Professor Smith Professor Mellon Professor Jones 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 Objects Class Professor
Basic Concepts of Object Orientation • Object • Class • Attribute • Operation • Relationships
CourseOffering :CourseOffering :CourseOffering number = 101 startTime = 900 endTime = 1100 number = 104 startTime = 1300 endTime = 1500 number startTime endTime What is an Attribute? In UML Object Class Attribute Attribute Value
Basic Concepts of Object Orientation • Object • Class • Attribute • Operation • Relationships
CourseOffering addStudent deleteStudent getStartTime getEndTime What is an Operation? In UML Class Operation
Basic Concepts of Object Orientation • Object • Class • Attribute • Operation • Relationships
UML Class Diagrams • A class diagram is used to show the existence of classes and their relationships in the logical view of a system Class diagrams show the classes of the system, their interrelationships (including inheritance, aggregation, and association), and the operations and attributes of the classes. Name • Associations • Aggregation • Generalization Relations Attributes Operations
UML Class Diagrams essentials ClassName • Class Diagrams • + Public • - Private • # protected • Thier basic relation ships • Association • Aggregation • generalization + attribute : type + coursename : string -operationt (): return type addStudent (): int
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.
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
Account balance name number Withdraw() CreateStatement() Savings Checking GetInterest() Withdraw() Withdraw() Example: Single Inheritance in UML Ancestor • One class inherits from another Superclass (parent) Generalization Relationship Subclasses Descendents
Example: Multiple Inheritance in UML • A class can inherit from several other classes FlyingThing Animal multiple inheritance Airplane Helicopter Bird Wolf Horse Use multiple inheritance only when needed, and always with caution !
Use case diagrams • 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.
Example Use Case diagram System boundary Actor: An actor is a person, organization, or external system that plays a role in one or more interactions with your system 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 Actor 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 Online shopping
Sequence Diagram • 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 • 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
Example Sequence Diagram Object: Class Operations Message Lifeline
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
Example Activity Diagram : processing an order. Start Fork Branch Merge Joint End
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
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.
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