Document 15071940

advertisement
Matakuliah
Tahun
: T0104 – Metode Perancangan Program
: 2010
AN INTRODUCTION TO OBJECT-ORIENTED
Pertemuan - 14
Pertemuan 14
An Introduction To Object-oriented
Bina Nusantara University
3
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
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
Introduction to object-oriented design
• Classes and objects
– Object is created from a template or pattern, called a class
which defines the basic relationship, attributes and
operations available to the objects of that class
– Each class in a system should bear a unique name
– Process of creating objects from classes is called
instantiation and an object is described as an instance of its
class
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
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
Introduction to object-oriented design
• Inheritance
– Allows a new object to inherit the same attributes and methods
as an existing object
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
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
Public and private access methods
• 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
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
Public and private access methods
• 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
• 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
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.
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.
Object Oriented Concepts
Download