chapter 12 object-oriented design for more than one class
TRANSCRIPT
![Page 1: Chapter 12 Object-oriented design for more than one class](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfea1a28abf838cb748a/html5/thumbnails/1.jpg)
Chapter 12
Object-oriented design for more than one class
![Page 2: Chapter 12 Object-oriented design for more than one class](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfea1a28abf838cb748a/html5/thumbnails/2.jpg)
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
![Page 3: Chapter 12 Object-oriented design for more than one class](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfea1a28abf838cb748a/html5/thumbnails/3.jpg)
12.1Further object-oriented design
![Page 4: Chapter 12 Object-oriented design for more than one class](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfea1a28abf838cb748a/html5/thumbnails/4.jpg)
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
![Page 5: Chapter 12 Object-oriented design for more than one class](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfea1a28abf838cb748a/html5/thumbnails/5.jpg)
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
![Page 6: Chapter 12 Object-oriented design for more than one class](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfea1a28abf838cb748a/html5/thumbnails/6.jpg)
Further object-oriented design• Relationship between classes
– Three types of relationship between classes:1. Relationship between two classes that
are independent of each other but one class might use the services the other provides – Association
2. Class may be made up of other classes or contain other classes that are part of itself – Aggregation or Composition
3. Class may inherit all the attributes and operations of a parent class but is given a unique name - Generalisation
![Page 7: Chapter 12 Object-oriented design for more than one class](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfea1a28abf838cb748a/html5/thumbnails/7.jpg)
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
![Page 8: Chapter 12 Object-oriented design for more than one class](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfea1a28abf838cb748a/html5/thumbnails/8.jpg)
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
![Page 9: Chapter 12 Object-oriented design for more than one class](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfea1a28abf838cb748a/html5/thumbnails/9.jpg)
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
![Page 10: Chapter 12 Object-oriented design for more than one class](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfea1a28abf838cb748a/html5/thumbnails/10.jpg)
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
![Page 11: Chapter 12 Object-oriented design for more than one class](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfea1a28abf838cb748a/html5/thumbnails/11.jpg)
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
![Page 12: Chapter 12 Object-oriented design for more than one class](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfea1a28abf838cb748a/html5/thumbnails/12.jpg)
• 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
Further object-oriented design
![Page 13: Chapter 12 Object-oriented design for more than one class](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfea1a28abf838cb748a/html5/thumbnails/13.jpg)
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
![Page 14: Chapter 12 Object-oriented design for more than one class](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfea1a28abf838cb748a/html5/thumbnails/14.jpg)
• 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
Object-oriented design with multiple classes
![Page 15: Chapter 12 Object-oriented design for more than one class](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfea1a28abf838cb748a/html5/thumbnails/15.jpg)
12.2Steps in creating an object-
oriented solution using more than one class
![Page 16: Chapter 12 Object-oriented design for more than one class](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfea1a28abf838cb748a/html5/thumbnails/16.jpg)
Steps in creating an object-oriented solution using more than one class• Four steps to follow to create an
object-oriented solution:1. Identify the classes and their
attributes, responsibilities and operations
2. Determine the relationship between the objects and those classes
3. Design the algorithm for the operation, using structured design
4. Develop a test or driver algorithm to test the solution
![Page 17: Chapter 12 Object-oriented design for more than one class](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfea1a28abf838cb748a/html5/thumbnails/17.jpg)
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.
![Page 18: Chapter 12 Object-oriented design for more than one class](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfea1a28abf838cb748a/html5/thumbnails/18.jpg)
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.
![Page 19: Chapter 12 Object-oriented design for more than one class](https://reader035.vdocument.in/reader035/viewer/2022062305/5697bfea1a28abf838cb748a/html5/thumbnails/19.jpg)
Summary• There are four steps for designing a
solution to a simple multiple-class problem:1. Identify the classes and their
attributes, responsibilities and operations.
2. Determine the relationship between the objects of those classes.
3. Design the algorithms for the operations using structured design.
4. Develop a test or driver algorithm to test the solution.