OOP is an object-oriented programming technique that combines data and instructions for processing that data into an object that can be used within the program. Object-oriented programming provides concepts that help
modelling complicated systems of real world into manageable software solutions.
The object-oriented approach, however, focuses on objects that represent abstract or concrete things of the real world. These objects are first defined by their character and their properties, which are represented by their internal structure and their attributes (data). The behavior of these objects is described by methods (functionality).
modelling complicated systems of real world into manageable software solutions.
The object-oriented approach, however, focuses on objects that represent abstract or concrete things of the real world. These objects are first defined by their character and their properties, which are represented by their internal structure and their attributes (data). The behavior of these objects is described by methods (functionality).
Object Oriented Concepts.:
Object :- Objects are structures that contain both data and procedures. For
example, a student is an object which has name and age.
example, a student is an object which has name and age.
To Create Object
Syntax. :-
Syntax. :-
CREATE Object: <object_name>.
Reference Object :- IN Ref. Object , After defining a class, you can create any
number of objects belonging to that class. Each object is
associated with the data of the type class with which it has
been created.
number of objects belonging to that class. Each object is
associated with the data of the type class with which it has
been created.
To Create Ref. Object
Syntax. :
Syntax. :
DATA: <object_name> TYPE REF TO <class_name>.
Class :- A class is a template that explains the details of an object Classes in
ABAP Objects can be declared by Global Class & Local Class.
ABAP Objects can be declared by Global Class & Local Class.
1. Global Class : Global classes and interfaces are defined in the Class Builder
(Tcode SE24) in the ABAP Workbench. They are stored centrally
in class pools in the class library in the R/3 Repository. All of the
ABAP programs in an R/3 System can access the global classes.
(Tcode SE24) in the ABAP Workbench. They are stored centrally
in class pools in the class library in the R/3 Repository. All of the
ABAP programs in an R/3 System can access the global classes.
2. Local Class : Local classes are define in an ABAP program (Tcode SE38) and
can only be used in the program in which they are defined.
can only be used in the program in which they are defined.
Every class will have two sections.
Class Definition : This section is used to declare the components of the classes
such as attributes, methods, events .
such as attributes, methods, events .
Syntax :-
CLASS <class_name> DEFINITION.
..........
..........
ENDCLASS.
Class Implementation : This section of a class contains the implementation of
all methods of the class. The implementation part of a
local class is a processing block.
all methods of the class. The implementation part of a
local class is a processing block.
Syntax :-
CLASS <class_name> IMPLEMENTATION.
...........
..........
ENDCLASS.
Components of a Class are as follow
· Attributes:-
Any data,constants,types declared within a class form the attribute of the class.
Any data,constants,types declared within a class form the attribute of the class.
· Methods:-
Methods are defined in the definition part of a class and implement it in the implementation part using the following processing block:
Methods are defined in the definition part of a class and implement it in the implementation part using the following processing block:
METHOD <meth>.
....
ENDMETHOD.
Methods are called using the CALL METHOD statement.They can access all of the attributes of a class.
....
ENDMETHOD.
Methods are called using the CALL METHOD statement.They can access all of the attributes of a class.
· Events:-
A mechanism set within a class which can help a class to trigger methods of other class.
A mechanism set within a class which can help a class to trigger methods of other class.
· Interfaces:-
Interfaces are independent structures that you can implement
in a class to extend the scope of that class.
Instance and Static Components:
Instance components exist separately in each instance (object) of the class and are referred using instance component selector using ‘->’
Static components only exist once per class and are valid for all instances of the class. They are declared with the CLASS- keyword Static components can be used without even creating an instance of the class and are referred to using static component selector ‘ =>’
Interfaces are independent structures that you can implement
in a class to extend the scope of that class.
Instance and Static Components:
Instance components exist separately in each instance (object) of the class and are referred using instance component selector using ‘->’
Static components only exist once per class and are valid for all instances of the class. They are declared with the CLASS- keyword Static components can be used without even creating an instance of the class and are referred to using static component selector ‘ =>’
Visibility of Components :
- Private : In Private Attributes, Variable & Methods can be access within class only .
- Public : In Public Attribute ,Variable & Methods can be access outside class only.
- Protected : Variable and Methods can be access within class as well as inherited class.
Declaration Syntax :
CLASS <class> DEFINITION.
PUBLIC SECTION.
...
PROTECTED SECTION.
...
PRIVATE SECTION.
...
ENDCLASS.
There are 4 type of Technique OF OOPS :-
PUBLIC SECTION.
...
PROTECTED SECTION.
...
PRIVATE SECTION.
...
ENDCLASS.
There are 4 type of Technique OF OOPS :-
- Polymorphism
- Inheritance
- Abstraction
- Encapsulation.
1. Polymorphism :-
It Is Behavior of Method Which Behave Differently in Difference Class.
Real Time Example :-
Crocodile: live indifferently on land or in the water. In water it’s Moment very fast compare to land. An animal lives in different character in different place.
2. Inheritance :-
Inheritance is the concept of passing the behavior of a class to another class.Inheritance is the process by which object of one class acquire the properties of another class.Advantage of this property is reusability. This means we can add additional features to an existing class with out modifying it.
Real Time Example :-
Father gives his property to child , father got that properties from child’s grandfather , so child is the taker and father is giver , hence father works as a base class and child as derived class .
3. Abstraction :-
Everything is visualized in terms of classes and objects.
Real Time Example :-
Birds: we invented flight based on the mechanism of Birds. So flight is derived form the base of birds.
4. Encapsulation :-
It is a process of binding or wrapping the data and the codes that operates on the data into a single entity. This keeps the data safe from outside interface and misuse. One way to think about encapsulation is as a protective wrapper that prevents code and data from being arbitrarily accessed by other code defined outside the wrapper.
Encapsulation = Data Hiding + Abstraction.
Real Time Example :-
Pen: Ink is the important component in pen but it is hiding by some other material.
Other Methods :-
Friends in oops :-
Certain Such Cases where a class would want access to other classes private attributes and methods in such scenario we can make use of the friends concept in classes.
Constructor :-
CONSTRUCTOR is a special type of method, it is executed automatically
whenever a object is created or instantiated.These methods are mainly used to
set default values in classes.
There are Two Types :-
1. Instance Constructor:-The Instance constructor of a class is the predefined
instance method 'CONSTRUCTOR'. & can only have
importing parameters, there will not be any exporting
Parameters.
2 . Static Constructor : The Static constructor of a class is the predefined
instance method 'CLASS CONSTRUCTOR'. these
methods will not have any importing and exporting
parameters.These methods will be executed only once.
0 comments:
Post a Comment