Professional Documents
Culture Documents
3/5/12
11
INTRODUCTION TO OOP
Objectives: Know the concept of OOP Know the difference between functional programming and OOP Know basic terminology in OOP Know the importance of OOP Know four design principles of OOP Know OOP programming languages
3/5/12
22
INTRODUCTION TO OOP
Object oriented programming is introduced as a new programming concept which should help one in developing high quality software. It attempts to solve the problem with only one approach by dividing the problems in sub-modules and using different objects Objects of the program interact by sending messages to each other.
3/5/12
33
INTRODUCTION TO OOP
Programming with objects is quite like working with real world objects. It groups operations and data into modular units called objects. These objects can be combined into structured networks to form a complete program, similar to how the pieces in a puzzle fit together to create a picture.
3/5/12
44
INTRODUCTION TO OOP
By breaking down complex software projects into small, self-contained and modular units, object orientation ensure that changes to one part of software project will not affect other portions of the software.
3/5/12
55
MAIN PROGRAM
GLOBAL DATA
FUNCTION 1
FUNCTION 2
FUNCTION 3
FUNCTION 4
FUNCTION 5
3/5/12
66
Structured Programming
There are features of structured programming: Emphasis is on doing things (algorithms) Using function Function & program is divided into modules Every module has its own data and function which can be called by other modules. Most of the functions share global data
3/5/12
77
Data move openly around the system from function to function Functions transform data from one form to another Employs top down approach in program design.
3/5/12
88
Data Function
3/5/12
99
Data is hidden and cannot be accessed by external functions. Objects may communicate with each other through functions. New data and functions can be easily added whenever necessary Follows bottom-up approach in program design.
3/5/12
11
Design is not very strong, hard to Design of the whole system could understand and difficult to be understand by others (even implement. doesnt have background on science computer) Using top-down approach. It breaks a program down into components until they cannot be composed anymore. MTS 3033 - OBJECT ORIENTED
3/5/12
15
iii. iii.
The principle of data hiding helps the programmer to build secure programs that cannot be invaded by code in other parts of program. It is easy to partition the work in a project based on objects. Object oriented system can be easily upgraded from small to large systems.
3/5/12
17
Communication
3/5/12
18
-Directly relate to the real world entities. -Can be a person, thing or concept (a noun). -Like a black box, therefore all the implementation is hidden.
3/5/12
19
has a Attribute - description of objects in a class Method - an action performed by an object (a verb) Identity (unique name)
3/5/12
20
21
data items (specify manufacturers name, model, year, etc.) Change a data item (color, engine, etc.) Display data items Calculate cost etc.
3/5/12 22
Class A generic
definition for a set of similar objects. Provides the specifications for the objects behaviors and attributes. An abstraction of a real world entity.
3/5/12
23
3/5/12
24
3/5/12
25
Messages Requests for the receiver objects to carry out the indicated method or behavior and return the result of that action to the sender objects
3/5/12
26
3/5/12
27
3/5/12
28
3/5/12
29
3/5/12
30
Abstraction
Data abstraction is a process to delete all unnecessary attributes and remain the necessary attributes to describe an object. Object in a program is an abstraction from a real object (in real world). Attributes characteristics, which can be seen. Behaviours actions that are done to an object. Figure 1.1 shows how data abstraction is done for class Student 31 MTS 3033 - OBJECT ORIENTED 3/5/12
Abstraction
OBJECT STUDENT CLASS STUDENT CHARACTERISTIC/ATRRIBUTES
NAME, MATRIK NUMBER, ADDRESS, IC NUMBER
ABSTRACTION
FIGURE 1.1
MTS 3033 - OBJECT ORIENTED 3/5/12 32
Abstraction
OBJECT BOX
OBJECT BOX ABSTRACTION
CLASS BOX
CHARACTERISTIC/ATRRIBUTES Length, width, depth
FIGURE 1.2
MTS 3033 - OBJECT ORIENTED 3/5/12 33
Abstraction
Focus only on the important facts about the problem at hand To design, produce and describe so that it can be easily used without knowing the details of how it works. Analogy: When you drive a car, you dont have to know how the gasoline and air are mixed and ignited. Instead you only have to know how to use the controls. Draw map
Encapsulation
Encapsulation
is a process of tying together all data and methods that form a class and control the access to data by hiding its information. It enables access to object just by using methods of that object. It is one of the security features in object-oriented programming (OOP). Figure 1.3 shows the concept of encapsulation for a class Student and Figure 1.4 for class Box.
MTS 3033 - OBJECT ORIENTED 3/5/12 35
Encapsulation
Student private : int matricNum int icNum char name[30] char address[100] public : double calculate_mark() void determine_mark() void print_result() FIGURE 1.3 Box private : float length float width float depth public : float calculate_volume() float area()
FIGURE 1.4
3/5/12
36
Encapsulation
Also known as data hiding Only objects methods can modify information in the object. Process of hiding the implementation details of an object. Access to manipulate the object data is through its interface (operations/ functions). Protects an objects internal state from being corrupted by other programs.
3/5/12 37
Encapsulation
Program maintenance is easier and less expensive because changes in the object data or implementation is only modified in one place Allows objects to be viewed as black boxes.
3/5/12
38
Polymorphism
the same word or phrase can mean different things in different contexts Analogy: In English, bank can mean side of a river or a place to put money move -
3/5/12
39
Inheritance
Inheritancea way of organizing classes Term comes from inheritance of traits like eye color, hair color, and so on. Classes with properties in common can be grouped so that their common properties are only defined once. Superclass inherit its attributes & methods to the subclass(es). Subclass can inherit all its superclass attributes & methods
3/5/12 40
An Inheritance Hierarchy
Vehicle Subcla sses Automobile Superclas s
Motorcycle
Bus
Sedan
Sports Car
Luxury Bus
School Bus
What properties does each vehicle inherit from the types of vehicles above it in the diagram?
MTS 3033 - OBJECT 3/5/12 41