Download presentation
Presentation is loading. Please wait.
Published byKelley Darrell Sutton Modified over 9 years ago
2
Object-Oriented Design Simple Program Design Third Edition A Step-by-Step Approach 11
3
Objectives To introduce object-oriented design To define objects, classes, attributes, methods and information hiding To list the steps required to create an object-oriented design to a problem 11
4
Introduction to Object-Oriented Design Object-oriented design asks that we interact with the problem in much the same way that we interact with our world — we treat it as a set of separate objects that perform actions and relate to each other An object-oriented program is a set of interacting objects rather than a set of functions In object-oriented design you need to identify the data in the objects as well as the processes or actions that can be performed on that data Objects are said to encapsulate their data, and the processes that act on those data 11
5
Objects An object can be considered as a container for a set of data, and the operations that need to be performed on it An object has the following properties: –It has a name that is unique for the lifetime of the object –It has data in the form of a set of characteristics or attributes, each of which has a value at any given point in time –There is a set of operations or methods that can be performed on the data –It is an instance (example) of a class In a computer program an object’s attributes are the properties or characteristics that describe it 11
6
Methods Objects receive messages from other objects, asking them to perform services or operations Each object has a number of methods or set of operations, sometimes called procedures or functions Methods can manipulate the values stored in an object’s attributes, but can only act on the data inside the object or on values passed to the object 11
7
Classes and Objects An object is created from a template or pattern, called a class, which defines the basic attributes and the methods available to objects of that class The process of creating objects from classes is called instantiation, and an object is described as an instance, or example of its class 11
8
Constructors The process of instantiating an object from the class template is performed by a special method known as a constructor Every class should have a default constructor that initializes the class attributes The constructor may: –have no parameters –have parameters that initialize the attributes with those particular values Classes can be progressively created from other classes by copying attributes and methods from the base classes 11
9
Constructors In a banking program, an Account class is created to manage customer accounts The class Account includes attributes such as accountName and balance, as well as methods such as deposit and withdraw money (refer to the diagram on page 177 of the textbook) Every ChequeAccount object that is created by the program, contains all the properties and methods of the Account class as well as the extra features of the ChequeAccount class 11
10
Information Hiding In object-oriented design, each object can be regarded as a ‘black box’ whose internal workings are hidden from all other objects This principle of information hiding simplifies the use of objects, because the rest of the system does not need to know how they are structured or how they perform their operations The goal of information hiding is to make the object as robust and independent as possible 11
11
Public and Private Methods An object’s methods, or set of operations, can be public or private The public methods of an object are those producing services requested by other objects Objects must be able to communicate and interact with the rest of the program, and this communication is achieved by the passing of messages 11
12
Steps in Creating an Object- Oriented Solution The steps in creating an OO solution are: –Identify the objects and the methods to be performed –Determine the relationship between the objects –Design the algorithms for the methods, using structured design –Develop the mainline algorithm 11
13
Programming Example Using Object-Oriented Design Example 11.2 Print student results Design a class to manage student results in a subject. Each student is identified by a unique student number. During the course of the subject, each student completes three assignments representing 40% of the final mark but each scored out of 100, and an examination, also scored out of 100 marks Use the four steps referred to in the textbook on pages 184 to the top of 187 to do this 11
14
Interface and GUI Objects An interface is a device in a program that connects the user’s responses to the computer’s actions Many popular programming languages provide a graphical user interface (GUI), which enables the programmer to select the elements of the program’s user interface from a pre-existing range of options These languages are call ‘visual’ languages, and include Visual Basic, Visual C, and Visual J Java also shares these features The user interface options may include windows, buttons, menus, boxes to hold text, drop-down lists and many more 11
15
Example 11.3 Library locater interface Use this example as a guide, on pages 187 to the middle of page 189 of the textbook Also refer to the diagrams on pages 188 and 189 of the textbook 11
16
Summary Object-oriented design is a fundamentally different process to procedural design Instead of decomposing the problem into functions, the problem is broken up into the objects in the system, and the attributes and methods for each object are identified Objects encapsulate their data and methods, and can be regarded as ‘black boxes’ for the purposes of large system design 11
17
Summary Objects are instantiated from classes that are templates defining the attributes and methods for objects of the type, but individual objects of the same type may store different data values in their attributes Interface design for visual programming languages uses object-oriented design principles Interface objects have methods and attributes 11
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.