Object Oriented Program Construction in C++

Object Oriented Program Construction in C++

PROCEDURAL LANGUAGES

Examples of procedural languages: C, Pascal, Fortran
A program in a procedural language is basically a list of instructions
As programs become larger they are usually broken down into smaller units, such as functions, procedures, subroutines
Functions can be grouped together into modules according to their functionality, objectives and tasks.
Structured programming is a programming paradigm that to a large extent relies on the idea of dividing a program into functions and modules.

PROBLEMS WITH STRUCTURED PROGRAMMING
Large number of potential connections between functions and data (everything is related to everything, no clear boundaries)
makes it difficult to conceptualize program structure
makes it difficult to modify and maintain the program
e.g. : it is difficult to tell which functions access the data
data and function are considered as two separate entities
makes it difficult to model things in the real world
complex real world objects have both attributes and behaviours
attributes
people: name, date of birth, eye color, job title
cars: horse power, number of doors, color
behaviours
people: ask a person to bring you a beer
cars: apply the brakes, turn on the engine
attributes and behaviors alone are sufficient to realistically
model real world objects but a unified view is needed

Object Oriented Approach
Encapsulation: integrate data and functions into one object
Data hiding : data is hidden to the outside world and can
only be accessed via the functions
In C++ functions are called membership functions in other
languages such as Smalltalk they are called methods
Data items are called attributes or instance variables
separation: objects interact with each other only via the their membership functions
separation helps to maintain the integrity of the entire program

ABSTRACTION
An abstraction is a named collection of attributes and behavior relevant to model a given entity for some particular purpose
SPARATION
independent specification of a visible interface and a hidden implementation
interface is some kind of contract between the object and the user of this object or module
separation is not restricted to object-oriented programming for example header files in standard C can be regarded as interfaces

EXAMPLES OF OBJECTS
physcial objects
vehicles in a traffic-flow simulation
electrical components in a circuit-design program
elements of a computer user environment
menus
graphic objects
data-storage constructs
arrays
linked lists
human entities
employees
students
collections of data
an inventory
an address book
user defined data types
time
complex numbers

CLASSES VERSUS OBJECTS
A class is a prototype specification from which
one can generate a number of similar objects
A class can be considered as an object factory.
An object is said to be a member or instance of a class
A class can be considered as a more complex
data structure than an ordinary built-in data type
Standard C already knows the struct command for
user defined data types:
struct complex
{
double re;
double im;
};
complex x;

Cours gratuitTélécharger le cours complet

Télécharger aussi :

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *