1 / 19

Chapter 12

Chapter 12. Object-oriented design for more than one class. Objectives. To describe relationships between classes To introduce a simplified unified modelling language To introduce polymorphism and operation overriding in object-oriented design

anchoret
Download Presentation

Chapter 12

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. Chapter 12 Object-oriented design for more than one class

  2. Objectives • To describe relationships between classes • To introduce a simplified unified modelling language • To introduce polymorphism and operation overriding in object-oriented design • To develop object-oriented design solutions to problems using more than one class

  3. 12.1 Further object-oriented design

  4. Further object-oriented design • Major advantage of object-oriented programming language is their usefulness in constructing large programs • In designing programs that use multiple classes, need to consider the relationship between the classes and therefore between the objects that are instantiated from those classes

  5. Further object-oriented design • Notations • Notation called standing for united modelling language (UML) • UML allows a designer to represent the relationship between classes as well as between objects

  6. Further object-oriented design • Relationship between classes • Three types of relationship between classes: • Relationship between two classes that are independent of each other but one class might use the services the other provides – Association • Class may be made up of other classes or contain other classes that are part of itself – Aggregation or Composition • Class may inherit all the attributes and operations of a parent class but is given a unique name - Generalisation

  7. Further object-oriented design • Association • Association between two classes is required when the classes need to interact or communicate for the program to achieve its purpose • Association are also called links

  8. Further object-oriented design • Aggregation and composition • Special forms of association where objects of one class, the container class, are made up or consist of other objects from other classes, the components classes • There are whole-part associations: one class is the whole that is made up of parts

  9. Further object-oriented design • Mildest form called aggregation, the part or component classes that make up the whole are able to exist without necessarily being part of the aggregation • Strongest form called composition, the component classes can only exist during the lifetime of the container object and cannot exist outside the composition

  10. Further object-oriented design • Generalisation • Class hierarchy that lets us group the shared attributes and operations into a top-level class, and then to define one or more lower-level classes with extra or different attributes and operations • The top-level class, also called the parent class or superclass, has shared attributes and operations, and the child classes or subclasses, inherit these, adding their own attributes and operations to make them distinct

  11. Further object-oriented design • Polymorphism • Describes the use of operations of the same name for variety of purposes • Operating overrides occurs when a parent class provides an operation, but the inheriting child class defines its own version of that operation • In another type of polymorphism, overloading, several operations in a single class can have the same name

  12. Further object-oriented design • Operation overriding • Occurs when a parent class provides an operation but the inheriting child class defines its own version of that operation • The operation in a subclass will override the operation in the superclass

  13. Object-oriented design with multiple classes • Operation overloading • Occurs when several operations in a single class have the same name but will act differently according to the number of parameters that are passed to the operation when it is called

  14. Object-oriented design with multiple classes • Scope of data • As soon as a project is created, the data that an object needs is brought within its scope • Attributes values are available to all the operations within the class and are visible to each operation

  15. 12.2 Steps in creating an object-oriented solution using more than one class

  16. Steps in creating an object-oriented solution using more than one class • Four steps to follow to create an object-oriented solution: • Identify the classes and their attributes, responsibilities and operations • Determine the relationship between the objects and those classes • Design the algorithm for the operation, using structured design • Develop a test or driver algorithm to test the solution

  17. Summary • It is important to understand the relationships between classes. • An association relationship occurs when two classes are independent of each other, but one class uses the services that the other provides. • The relationship between a parent class and a child class is called generalisation.

  18. Summary • Polymorphism refers to the same method name being used in different classes to perform a variety of purposes. • Operation overriding occurs when a parent class provides an operation, but the inheriting class defines its own version of the operation. • Operation overloading occurs when several operations in a single class have the same name, but will act differently according to the number of parameters that are passed to the operation when it is called.

  19. Summary • There are four steps for designing a solution to a simple multiple-class problem: • Identify the classes and their attributes, responsibilities and operations. • Determine the relationship between the objects of those classes. • Design the algorithms for the operations using structured design. • Develop a test or driver algorithm to test the solution.

More Related