Header Ads

Basics of Object oriented Programming

Object-oriented programming (OOP) is aprogramming language model organized aroundobjects rather than "actions" and data rather than logic.

CLASSES
Classes are the central element of object-orientation. A Class describes a
general element or a general concept. Classes realize an abstract data type. Classes
contain components like: Attributes, Methods and Events.


OBJECTS / INSTANCES
An object is nothing more than an instance of a Class.
Object - A person, place, thing, concept, or event that is applicable to the
system at hand. Objects both know things (i.e., they have data) and they do things
(i.e. they have functionality).


ATTRIBUTES
Attributes can take on values within an object at runtime. The sum of all
attributes and their values describes the state of an object.
Attributes can be defined as instance dependent as well as Class dependent.
Class attributes (Class attributes are also called static attributes.) are not tied to a
single instance, rather they "belong" to all instances of the Class. These attributes
exist only once in main memory. Instance-dependent attributes exist once per
instance and are tied to a single instance.


METHODS
As well as attributes, Classes have so-called Methods. While attributes
describe the static structure of a class and its objects, Methods describe the behavior
of objects within a class. With the help of methods, the system provides operations,
services and functions. Via methods, a user can manipulate the objects in a class or
also the class itself. As for attributes, there are instance-dependent as well as classdependent
(static) methods. ABAP Objects differentiate between instance-dependent
and class-dependent methods via the ABAP keywords METHODS or CLASS-METHODS
used in the definition part.

CONSTRUCTOR

The constructor is a method which runs automatically during the creation of an object.
The constructor allows you to define IMPORTING-parameters.


VISIBILITY
An important feature of object-orientation is the encapsulation of attributes
and methods - ultimately of functionality - in classes. A class guarantees its user
specific properties and specific behavior. The sum of these properties is called the
class interface. The Visibility mechanism defines the class interface which is available
to the users.
There are three commonly defined types of visibility in object-oriented technology:
Public
The relevant class component (attribute, method, event etc.) is visible to all classes.
Protected
The relevant class component (attribute, method, event etc.) is visible to the class
itself and all inheritors. (We will return to the terms Inheritor and Inheritance later in
this document.)
Private
The relevant class component (attribute, method, event etc.) is only visible to the
class itself.


EVENTS
Events are recognized in particular by programming interfaces of the GUIs
(Windows, Motif, etc.), for example, you can "ask" the GUI to trigger an event if the
user moves the mouse over a specific part of the screen. When the event occurs you
are telling the GUI to change the shape of the mouse pointer.
Events allow for the loose coupling of components (classes or objects) in a
system. The event trigger does not normally know at the time of coding who is going
to react to the event. Those components, which want to react to the event, register
at the event runtime, in that they tell the runtime environment which method is to
be executed when the event is raised. In this way many components can register for
an event.
Event handler methods can proceed synchronously as well as asynchronously.
At present, ABAP Objects only supports synchronous calling of the event handler
method.



INHERITANCE
Inheritance defines the relationship between classes, in which a class
(subclass) uses the structure and behavior that has already been defined in one or
more other classes (superclasses). So simply this means "Inheritance is about
reuse!".
Allow me to use a concrete example to explain inheritance: Collection.
A collection is any number of objects (more precisely object references).
However, there could be many types of collection. Therefore, I will implement each
type of collection as a class. In principle this approach is correct. However, you will
soon establish that all collections have several components in common like:
1. Each class requires a method in order to add objects to a collection.
2. Each class requires a method in order to delete objects from a
collection.
3. Each class has a method which identifies the number of object
references in the collection and so on.
Inheritance is the solution to this situation. You implement all of the
similarities in the class which is Superclass. You then implement the individual types
of collection in their own classes which are Subclassesof the Superclass. As a
subclass, these classes inherit all of the components of the Superclass. Attributes,
methods and events are inherited. In addition, you can implement additional
attributes, methods and events in the subclass.

POLYMORPHISM
Polymorphism occurs, where classes implement the same functionality with
different methods (one functionality, several methods but the same name). This can
occur via an inheritance relationship, in that the methods belonging to the superclass
are redefined in the subclasses and implemented differently. ABAP Objects requires
the method names to be the same and the signature to be the same (signature =
method interface).
Polymorphism can be achieved in 2 ways:


(1) Two independent classes implement methods with the same names and the same
signature with the intention, that the methods should be called dynamically from a
third location.
(2) A superclass implements a method, and in a subclass you want to re-implement
the same method, as the superclass implementation is not suitable for the subclass.
The first scenario will not occur very often in ABAP Objects, as the interface concept
was created precisely for such cases.


INTERFACES
TheInterface concept describes a class interface. You can define the same
components in an interface that you can in classes, however without implementing
them.
Classes can implement interfaces, and subsequently be addressed via these
interfaces. This opens an additional mechanism of polymorphism, however without
being dependent on inheritance. This combination of classes with simple inheritance
and interfaces is more highly regarded by many experts than full multiple
inheritances.
In addition to object references (DATA: instance TYPE REF TO CL_CLASS)
there are also Interface References (DATA: reference TYPE REF TO CL_INTERFACE).
A class which implements a specific interface can be addressed via this interface
reference. Using such an interface reference, you can access the components defined
in the interface. In this way a user can view different classes through the 'spectacles'
of an interface and address them in a uniform manner.
Interfaces therefore define specific, generic functionality. In contrast to
classes, interfaces generally have not only many users, but also many implementers.


Please check the below link to check each OOP programming  language basics.



It will be very helpful if you can visit my youtube channel 
https://www.youtube.com/user/nkbhatt

Donate ETH:  0x4ae0be2fd21779f39d2e3be51aac3973de67b37a
Donate BTC: DRq7gASSRVV3SZxqLHpTe2PQ3chuYFw1jo
Donate LTC: LWqCXBUBtHNQL2chM4AQhCmJ7C3eSNU5bJ
Donate:DOGE: DRq7gASSRVV3SZxqLHpTe2PQ3chuYFw1jo



Powered by Blogger.