1 / 60

EC-241 Object-Oriented Programming

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.

taini
Download Presentation

EC-241 Object-Oriented Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 Abstraction Encapsulation Modularity Hierarchy Basic Principles of Object Orientation

  4. Salesperson Not saying Which salesperson – just a salesperson in general!!! Product Customer What is Abstraction? Manages Complexity

  5. What is Encapsulation? • Hide implementation from clients • Clients depend on interface How does an object encapsulate? What does it encapsulate? Improves Resiliency

  6. What is Modularity? • The breaking up of something complex into manageable pieces Order Entry Order Processing System Order Fulfillment Billing Manages Complexity

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

  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.htmhttp://www.inconcept.com/JCM/April1998/halpin.html

  11. Specifying Unified Modeling Language (UML) The Unified Modeling Language (UML) is a standard  language for Constructing Documenting Visualizing Communications Business Modeling

  12. UML: Different Views Users (Use Case Diagrams) Designers (Class Diagrams) Analyzers (State Transition Diagrams)

  13. UML: Different Views Analyzers (Activity Diagram) Analyzers (Sequence Diagrams)

  14. Introduction to Object Oriented Design • Basic Principles of Object Orientation • Unified Modeling Language (UML) • Basic Concepts of Object Orientation

  15. Basic Concepts of Object Orientation • 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 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)

  20. Basic Concepts of Object Orientation • Object • Class • Attribute • Operation • Relationships

  21. 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

  22. 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

  23. Representing Classes in UML • A class is represented using a compartmented rectangle a + b = 10 Professor Professor Clark

  24. 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)

  25. 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

  26. Basic Concepts of Object Orientation • Object • Class • Attribute • Operation • Relationships

  27. 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

  28. Basic Concepts of Object Orientation • Object • Class • Attribute • Operation • Relationships

  29. CourseOffering addStudent deleteStudent getStartTime getEndTime What is an Operation? In UML Class Operation

  30. Basic Concepts of Object Orientation • Object • Class • Attribute • Operation • Relationships

  31. 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

  32. 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

  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

  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() Savings Checking GetInterest() Withdraw() Withdraw() Example: Single Inheritance in UML Ancestor • One class inherits from another Superclass (parent) Generalization Relationship Subclasses Descendents

  37. 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 !

  38. 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.

  39. 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

  40. Use case example

  41. 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,

  42. 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

  43. Example Sequence Diagram Object: Class Operations Message Lifeline

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

More Related