Object Oriented Design:

 

Structural Approach:

 

Programs are made up of data structures and functions.  Data is kept in separate files and methods in others. For example header files in C language.

 

Object Oriented Approach:

 

Object Oriented can do an even better job by providing data abstraction known as encapsulation, which is data hiding.  The approach is as follows:

 

1.        Divide the program into logical parts, which are called classes (abstraction = closed box - what is in it?).

2.        Each part is totally independent of the rest of the program.

3.        Each part has its own data and methods enclosed within it  (encapsulation).

4.        Data and methods within any part are hidden and cannot be modified by any code outside the class (information hiding).

5.        You can use any of these parts (classes) by simply calling the part name and adding the task (method) name to the part       (class_1.do_anything).

6.        The program has one "main()" method that manages the entire program.

 

 

Objects:

 

What is an object?

 

According to Kernighan and Ritchie an object is defined as follows:

 

"An object, sometimes called variable, is a location in storage, and its interpretation depends on two attributes, its storage class and its type. The storage class determines the lifetime of the storage associated with the identified object; the type determines the meaning of values found in the identified object"


This defines an object as a region of storage that has:

1.        Scope

2.        Type

 

SCOPE:

Scope means when and to whom the object is visible or accessible (local or global scope - dynamic or static scope).

 

Type:

 

A type is translated into the following:

 

1.        What does the storage look like:  space = number of bytes

2.        What values can be stored in that type

3.        What kind of operations can be performed on that type

 

Abstraction:

 

According to Webster Dictionary the word "Abstraction" can have one of the following meaning:

 

1.        NOT CONCRETE

2.        Brief statements of the essential thoughts of a book, article, speech or court record.

3.        Summary

 

 

Programming Definition of Abstraction:

In programming design Abstraction is a mechanism which unifies the representation (storage) and the operations (+, - , = , ...etc) of a programmer defined data type.    Abstraction is the specification of data type that must be understood in order for the programmer to use the data type.  The programmer needs not know the details of how the system creates, stores or manipulates the data type.  For example, a flowchart is an abstraction of a program to be coded.  The following definition of method "anyThing" in example #4.1 has the integer type variable "joe" which is another example of abstraction:

 

 

     int anyTthing( ... arguments ...)

       {

         int   joe = 10;

         ...

       }

 

The programmer has to know that by defining the variable "joe", the system would create a storage and a set of operation that can done on that variable.  The system would also make the variable (scope) accessible only within the method "anyThing". The programmer may not need to know how the system assigns the memory space needed the type checking or any operations performed on the dada defined.

 

 

Information Hiding:

 

 Information Hiding means that the details of how things are done to an object or within a method are completely hidden from the user.  The user can only call the method or access the object, but can not modify the performance, the mechanism of the method or the system handling of the object.  For example, the programmer can call the square root method provided by the language as follows:

 

     realValue = sqrt(floatValue);

The programmer can not modify the code for square root method since its code is hidden from the programmer.  The programmer can access the value stored in the variable "realValue" but can not change the system handling of bit presentation of the memory storage of that variable.

 

 Encapsulation:

 

Encapsulation involves both abstraction and information hiding. It is translated into the following:

 

1. Abstraction:

The user does not need to know the hidden information in order to use the object or the method.

2.Information Hiding:

The user is not permitted to manipulate the hidden information if the user wishes.

What is an object in Oriented Object?

 

Object Oriented defines an object as a collection of data objects (variables) and a set of member methods.  An object is a functional object, which means that the object is not only a storage place in memory but also a set of methods that perform certain tasks on this storage.

 

OBJECT = STORAGE + METHODS

 

An object is a functional type that contains within it the necessary data objects (variables) plus a set of methods (known as member methods) that are needed to perform certain tasks.

 

Object oriented provides Encapsulation with flexibility.  Member (data and methods) within an object can be of the following types (Access Specified):

 

1.        Private

Class members (data and methods) can only be accessed by any one inside the object but are hidden from anyone outside the object. Class's objects and member methods are private by default.

 

2.        Public

Class members (data and methods) can be accessed by anyone in the program.  Structure's data objects and member methods are public by default.

 

3.        Protected

Only the following can access data objects and member methods:

A.          Member methods

B.           Derived class member methods

 

Class:

 

Object Oriented provides a new way of declaring a user-defined data type that has functionality.  This user-defined data type contains both the data objects and the methods that perform certain tasks on them.  The new type is known as a class.  A class or an ABSTRACT data type is a way of grouping logical data and the associated methods within one object (class).  The definition of this logical entity is called ENCAPSULATION.  Note that the class is also an object (variable).

 

 

class className

{

member data object list       - 0 or more

member method list              - 0 or more

}

 

 

 Class Instantiation and Instance:

 

                When a class is declared, no memory is allocated for this class until a class definition or creating an object is done. Creation of an object from a class is called “Instantiating an Object” and the object created is called “an instance of that class”.

 

 

Inheritance:

 

                Inheritance is a mechanism that allows type and subtype share characteristics the same way genes are passed from parents to children. Inheritance allows the member of one class to be used by another class as if the members of the inherited class were the members of inheritee class.   Inheritance is the relationship between the parent class and child class. The parent class is called “super-class” and child is “subclass”.   The super-class members can be referenced by the subclass and are said to be inherited by the subclass.

 

Super-Class:

 

                A super-class is a previously declared class for the class being declared.  A class is said to be inherited from its super-class.

 

Extended and Access Control:

 

                Classes inherit members of the super class, but the visibility modifiers control the level of members’ access.  There are four types of visibility modifiers as follows:

 

1.        “public”

2.        “private”

3.        “protected”

4.        default (package)

 

 

Public:

 

                If a super-class is declared “public”, all super-class’s “public” members become “public” member of subclass, all super-class’s  “protected” members become the “protected” members of subclass, but all super-class’s package (default) members are only inherited or accessible to subclasses inside the package.

 

Private:

 

                If a super-class declared  “private”, none of its members are accessible by the subclass.

 

Protected:

 

                If a super-class is declared  “protected”, all super-class’s “public” members become “protected” member of subclass, all super-class’s  “protected” members become the “protected” members of subclass, but all super-class’s package (default) members are only inherited or accessible to subclasses inside the package.

 

Default (package):

 

                If a super-class is declared package (default), all super-class’s “public” members become “public” member of subclass, all super-class’s  “protected” members become the “protected” members of subclass, but all super-class’s package (default) members are only inherited or accessible to subclasses inside the package.

 

 

Polymorphism:

 

                The Webster Dictionary defines polymorphism as “The occurrence of different forms, stages, or types in an individual”.  In Object Oriented it means that an object can perform different tasks for different implementation.  For example, a declared class using inheritance that represents a Bear can be made to print different types of bear from polar bear to Panda bear.