Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 11 An introduction to object-oriented design.

Similar presentations


Presentation on theme: "Chapter 11 An introduction to object-oriented design."— Presentation transcript:

1 Chapter 11 An introduction to object-oriented design

2 Objectives To introduce object-oriented design To define objects, classes, attributes, operations and information hiding To introduce public and private operations, accessors and mutators To list the steps required to create an object-oriented design solution to a problem

3 11.1 Introduction to object-oriented design

4 Objects - Real world

5 Introduction to object- oriented design Characteristics/Attributes Size/liquid capacity Make Tasks it can perform/Methods Filling Pouring Handle to pass messages

6 Introduction to object- oriented design Characteristics/Attributes Make Model Number of doors Engine size Actions it can perform/Methods Accelerate Stop Brake Turn

7 Introduction to object- oriented design Objects – Can be considered as a container for a set of data and the operations that need to be performed on it – Objects have the following properties It has an identity that is unique for the lifetime of the object It has data in a form of a set of characteristics or attributes A set of operations or methods that can be performed on the date It is a instance (example) of a class

8 Introduction to object- oriented design Classes and Objects – Describes groups of objects that share some common property – Each class in a system should bear a unique name – Each object is an instance of the class it belongs – Process of creating objects from classes is called instantiation

9 Introduction to object- oriented design Classes and Objects – Inheritance – the ability of an object to have the same attributes and methods common to the class of objects it belongs.

10 Introduction to object- oriented design Attributes – An object’s data is stored in attributes – Attributes are the properties or characteristics that describe that particular object – Objects of the same class will have an identical set of attributes

11 Introduction to object- oriented design Methods – Objects usually have a set of operations called ‘methods’ – Includes all operations required to be performed on an object, and are the same as modules in procedural programming

12 Introduction to object- oriented design Class diagram – Object-oriented programming requires classes, attributes and methods to be represented in a class diagram – Consists of a rectangular box divided into three section with the name of the class at the top, the attributes of the class in the middle and the methods at the bottom

13 Introduction to object- oriented design Class name Attribute 1 Attribute 2 … Method 1 Method 2 … Car Make Model Doors BodyLength EngineSize Color Speed Accelerate() Stop() Brake() Turn(direction)

14 Introduction to object- oriented design SVU478 : Car Make = “Toyota” Model = “Corolla” Doors = 5 BodyLength = 200 EngineSize = 4 Color = “Red” Speed = 60 Accelerate() Stop() Brake() Turn(direction) RVJ635 : Car Make = “Ford” Model = “Falcon Doors = 4 BodyLength = 300 EngineSize = 6 Color = “Blue” Speed = 0 Accelerate() Stop() Brake() Turn(direction)

15 Introduction to object- oriented design Encapsulation and information hiding – Objects are said to be encapsulate (enclose together in a single indivisible unit) – In object-oriented design, each object can be regarded as a ‘black box’ whose internal workings are hidden from all other objects

16 OO Design - Example Design a class that will receive a fraction in the form of a numerator and a denominator, convert that fraction to a percentage and print the result. Your program is to use OO design techniques InputProcessingOutput nume deno Get nume, deno Convert fraction to percentage Print percentage percentage Defining Diag. in Procedural technique

17 OO Design - Example Class diag. in OO design Fraction Nume Deno setFraction() convertFraction() printPercentatge()

18 11.2 Public and private access methods

19 Necessary to consider whether the attributes and operations of an object are to have private or public access This concept is called ‘visibility’ Private access means that the attribute and methods are invisible to the rest of the system Public access means that the operation is visible other objects

20 Public and private access methods Instantiating objects – Every time an object is instantiated from a class, a special operation, or set of instructions known as a ‘constructor’ method is called or invoked – Constructors may: Have no parameters – new objects is assigned all the default vales for its attribute Have parameters that initialise the attributes with specific values

21 Accessors and mutators – The values in the attributes of an object should be available to all operations in that object, but hidden from external objects – Accessor operations pass attribute values to external objects – Mutator operations enable objects to change the values stored in attributes Public and private access methods

22 Message – Communication is achieved when one object passes a message to another – Message from one object to another usually initiates the processing of an operation in the receiving object Public and private access methods

23 11.3 Steps in creating an object- oriented solution

24 Three steps in creating an object- oriented solution for a problem with just one class: 1.Identify the objects and their attributes, responsibilities and operations 2.Design the algorithms for the operations and methods using structured design 3.Develop a test or driver algorithm to test the solution

25 Summary Object-oriented design focuses on the objects that make up a program rather than on the processes. An object can be defined as a container for both a set of characteristics and a set of operations that can be performed on the data. Objects encapsulate their data and operations, and can be regarded as ‘black boxes’ for the purposes of large system design.

26 Summary Operations that are accessible by external objects are described as having public access. Operations that are internal to the object are described as having private access.

27 Summary The steps in designing an object- oriented solution for a programming problem are: 1.Identify the classes and their attributes, responsibilities and operations. 2.Design the algorithms for the operation, using structured design. 3.Develop a test or driver algorithm to test the solution.


Download ppt "Chapter 11 An introduction to object-oriented design."

Similar presentations


Ads by Google