Development Software 2 (DOS200S)
2013
OBJECT ORIENTED
PROGRAMMING CONCEPTS
Compiled By WH Olivier 2013/01/29 1
Introduction Classes & Objects
2013/01/29 Compiled By WH Olivier 2
In the real world, an object can be anything that we can see
around us. An object can be of a certain type. A dog, for
instance is a type of animal.
Animals is characterized by the way they look and the way they
behave.
A dog belong to the animal class and therefore inherits the
properties and behavior of an animal.
A Dalmatian again, is a type of dog and would inherit the
properties and the behavior of a dog.
Therefore, we can differentiate between a class and an
object.
A Class is a blueprint or template for an object. A class
specifies or defines an objects properties and behavior.
An Object is an instance of a class or type. Two dogs
would possess different values for their color and size
properties.
A Car Class
2013/01/29 Compiled By WH Olivier 4
The creation of a car typically begins as engineering drawings. The drawings would include all the features, components and properties of the car. Included in the design would be all the mechanisms that will allow the car to perform some function.
For example, in order for a car to accelerate, pressing the pedal would perform that function.
Unfortunately you cannot drive the drawings. Building a car from that engineering drawings would be creating an instance a car. The car instance (object) would possess all the features and properties of that car class.
Once the car is there you can drive it, press the accelerator pedal and that would course the car to move faster
Read more… Introduction to classes and objects
Objects in Business
2013/01/29 Compiled By WH Olivier 5
In the business world, companies deal with various
types of data. Data elements can be grouped
because they are related. For example all the data
about a customer are grouped and can be
represented as a Customer object.
Other objects would be Employee, Order, Invoice, etc.
Read More on Business Objects
Business Objects
Introduction to SAP Business Objects
Program design use to be (and still is being used)
procedural. Procedural programming is creating a step
by step program where the program is a sequence of
instructions . Execution of the program starts at the
top and continues executing code line by line till the
bottom.
Procedural programming also include functions
(smaller programmes) where the program can change
data which it has access to via the functions.
With procedural programming the data and the
operations on the data is separate and data is being
passed and changed via the functions.
Compiled By WH Olivier 2013/01/29 6
In Object Oriented Programming, things are being viewed as entities called objects. Objects is the grouping of data and its related functionality into one unit.
OOP is a design philosophy used in different programming languages. Everything within OOP is grouped as a self sustainable object. OOP thus have a re-usable component where objects can be used in many other programs.
An Object is entity or thing that can perform a set of related activities / behavior (Eg. A CAR can drive, brake) and have particular characteristics / properties ( Eg. A Car have color, engine capacity)
A Class is simply a representation of a type of object. It is a blueprint for the describing the detail of an object.
Compiled By WH Olivier 2013/01/29 7
The encapsulation is the inclusion within a program
object of all the resources need for the object to
function - basically, the methods and the data.
In OOP the encapsulation is mainly achieved by
creating classes, the classes expose public methods
and properties.
The class is kind of a container or capsule or a cell,
which encapsulate the set of methods, attribute and
properties to provide its indented functionalities to other
classes. In that sense, encapsulation also allows a
class to change its internal implementation without
hurting the overall functioning of the system. Compiled By WH Olivier 2013/01/29 8
Abstract classes, which declared with the abstract
keyword, cannot be instantiated. It can only be used
as a super-class for other classes that extend the
abstract class. Abstract class is the concept and
implementation gets completed when it is being
realized by a subclass. In addition to this a class can
inherit only from one abstract class (but a class may
implement many interfaces) and must override all its
abstract methods/ properties and may override virtual
methods/ properties.
Compiled By WH Olivier 2013/01/29 9
Abstract data types can be implemented via classes and object.
When defining a new class and creating a object based on that class, you created an abstract data type.
Abstract data types are purely theoretical entities, used (among other things) to simplify the description of abstract algorithms, to classify and evaluate data structures, and to formally describe the type systems of programming languages.*
* http://en.wikipedia.org/wiki/Abstract_data_type Compiled By WH Olivier 2013/01/29 10
Inheritance & Composition
The ability for a new class to be created from an
existing class by extending it is known as
inheritance.
When one class contains another class as one of
its members, that is known as composition
The following slide explains it by use of a diagram
Compiled By WH Olivier 2013/01/29 11
dataType
-dMonth: int
-dDay: int
-dYear: int
+setDate(int, int, int) : void
+getDay() const: int
+getMonth() const: int
+getYear() const: int
+printDate() const: void
+dateType(int = 1, int = 1, int =1900)
partTimeEmployee Class
+print() const : void
+calculatePay() const: double
+setNameRateHours(string, string,
double, double) : void
+partTimeEmployee(string = “ “,
string = “ “, double = 0, double
= 0)
-payRate : double
-hoursWorked : double
personType Class
+print() const : void
+setName(string, string: void
+getFirtsName() const: string
+getLastName() const : string
+personType(string = “ “, string = “
“)
-firstname : string
-lastname : string
personalInfo Class
+setPersonalInfo(string, string, int,
int, int, int) : void
+printPersonalInfo() const : void
+personalInfoType(string = “ “,
string = “ “, int = 1, int =1,
int = 1900, int = 0)
-name : personType
-bDay : dateType
-personID: int
INHERITANCE
partTimeEmployee
“is a” type of
personType
COMPOSITION
personalInfo “has a”
dateType as one of
its members
COMPOSITION
personalInfo “has a”
personType as one
of its members
INHERITANCE and COMPOSITION
Compiled By WH Olivier 2013/01/29 12
What is Polymorphism: Is a generic term which means ‘many shapes’ Is also means the ability to that one operation be performed by a wide
range of different things. Simply stated, a operation will perform differently depending on the way it is called and by which other thing it is being requested.
Method Overloading, Operator Overloading and Method Overriding is the different techniques used to achieve polymorphism
What is Method Overloading The ability to define several methods with the same name
What is Operator Overloading Operators like +, -, *, == are treated as polymorphic functions and as
such have different behaviours depending on the way it is called (arguments)
What is Method Overriding Is used in inheritance where a sub-class can override a specific
implementation of a method that is already provided by the super-class
Compiled By WH Olivier 2013/01/29 13
Reference http://saimaterial.wordpress.com/2007/09/14/1what-
is-the-difference-between-object-oriented-programming-and-procedural-programming/
http://www.codeproject.com/Articles/22769/Introduction-to-Object-Oriented-Programming-Concep
http://math.hws.edu/eck/cs124/downloads/OOP2_from_Univ_KwaZulu-Natal.pdf
http://www.deitel.com/books/cpphtp5/cpphtp5_03_sample.pdf
http://publib.boulder.ibm.com/infocenter/dmndhelp/v7r5m1/index.jsp?topic=%2Fcom.ibm.wbpm.wid.data.doc%2Fbo%2Ftopics%2Fcbo.html
http://help.sap.com/saphelp_40b/helpdata/en/7e/5e11a84a1611d1894c0000e829fbbd/content.htm
Compiled By WH Olivier 2013/01/29 14