Object oriented programming deals with partitioning the entire programs into groups using data structures called 'objects' and assigning attributes and methods to them.Object oriented programming consists of two things:
1) classes
2) objects
CLASSES:
A class is a group of attributes of the same kind. it is used to impart object orientedness to a program. for example,pen, pencil, rubber etc belongs to a class stationary.A class is a blueprint for a data type. it cant be implemented itself, we always need an object to implement a class in a program.simple example using classes :
1) classes
2) objects
CLASSES:
A class is a group of attributes of the same kind. it is used to impart object orientedness to a program. for example,pen, pencil, rubber etc belongs to a class stationary.A class is a blueprint for a data type. it cant be implemented itself, we always need an object to implement a class in a program.simple example using classes :
class abc
{
public:
double length; // Length of a box
double breadth; // Breadth of a box
double height; // Height of a box
};
A class can be used with 3 keywords:
1) public-This means the attributed included in that class can be used even outside that class
2) private-This means attributes of a class are used within that class only
3) protected-used basically in inheritance
OBJECTS:
Objects are the physical representation of classes. Classes cant be implemented without the help of the
objects.Classes are the blueprints for objects.
Syntax for creating object:
classname objectname;
for example:
box box1;
here box is a classname whereas box1 is an objectname.
PRINCIPLES OF OOPS:
1)Encapsulation
Encapsulation is the process of hiding of data implementation by restricting access to accessors and
mutators. Mutators are open ways that are used to update the state of an object, whereas concealing
the implementation of exactly how the data gets revised.
An accessor is a technique which is used to request an object about itself. In
OOP, they are generally in the form of properties, that have, under standard conditions, a get method,
that is an accessor method.However, accessor methods are not confined to properties and can be any
kind of public method that offers information about the state of the object.
2)Abstraction
Data abstraction is the easiest of principles to figure out. Data
abstraction and encapsulation are directly tied together, because a
plain definition of data abstraction is the growth and development of classes,
objects, types in terms of their interfaces and functionality, instead
of their implementation details. Abstraction denotes a model, a view,
or various other focused representation for an actual item. Its the
development of a software object to symbolize an object we can find in
the real world. Encapsulation hides the details of that implementation.
Abstraction is employed to manage complexity. Software developers use abstraction to
decompose complex models into smaller elements. As development
progress, software engineers know the overall performance they can expect from as
yet undeveloped subsystems. Thus, programmers are not burdened by
thinking about the ways in which the execution of later on subsystem
will influence the model of previous development.
3)Inheritance
Inheritance as the name suggests implies inheriting properties from one class to another.Let us take an
example,In a family child inherits properties/genes of his parents,his/her parents inherits properties/genes
of their parents and so on.The same happens in the case of classes.A class can inherit certain properties
from some other class.The class which inherits the properties from some other class is referred to as
child and the class from which the properties are inherited is referred to as base class or super-class.
4)Polymorphism
Polymorphism means a single name, numerous types. Polymorphism
manifests itself by having multiple ways all with similar name, but
slightly dissimilar functionality.
There are actually two basic types of polymorphism. Overriding, additionally
known as run-time polymorphism, and overloading, that is referred to as
compile-time polymorphism. This dissimilarity is, for method
overloading, the compiler decides which method will be
executed, and this choice is done when the code gets compiled.
Which method is going to be used for method overriding is determined at
run-time depending on the dynamic nature of an object.
Wednesday
//
Labels:
c++
//
0
comments
//
0 comments to "Introduction to object oriented programming"
Powered by Blogger.
Post a Comment