Академический Документы
Профессиональный Документы
Культура Документы
Abstract class
Interface
Final class
Inheritance
Constructor
Static/Instance
Persistence class
Casting
What is OOPS?
Type of problem-solving method in which the software solution reflects real-world objects.
Data is hidden and cannot be accessed by external functions.
Complex software systems become easier to understand.
OO systems are easier to scale by using the concept of reusability.
Objects:
An object is a section of source code that contains data and provides services. The data forms the
attributes of the object. The services are known as methods (also known as operations or functions).
They form a capsule which combines the character to the respective behavior. Objects should enable
programmers to map a real problem and its proposed software solution on a one-to-one basis.
Classes:
Structure of Class
CONSTRUCTORS:
Constructors are special methods that are triggered when an object is instantiated from a class.
They are necessary when you want to set the initial state of an object dynamically.
Like normal methods, there are two types of constructor - instance constructors and static
constructors.
Static Methods
Static methods are methods which can be called irrespective to the class instance. You can
access only static attributes and static events within the Static method.
This is how you declare and call static method:
Instance methods are methods which can be ONLY called using the object
reference. Instance methods can access instance attributes and instance events.
This is how you declared and call instance method:
An abstract method is defined in an abstract class and cannot be implemented in that class.
Instead, it is implemented in a subclass of the class. Abstract classes cannot be instantiated.
A final method cannot be redefined in a subclass. Final classes cannot have subclasses. They
conclude an inheritance tree.
Differences
Since both abstract class and interface are different entity, they have few differences:
Multiple Inheritance: We can achieve multiple inheritance using Interfaces. Since ABAP
doesn’t support more than one Super class, we can have only one abstract class as Super
class.
New Functionality: If we add a new method in the Interface, all the implementing
classes have to implement this method. If we don’t implement the method, it would
result into Run-time error. For Abstract class, if we add a non-abstract method, it’s not
required to redefine that in each and every inherited class.
Visibility: All interface components are PUBLIC by default. For Abstract class, we can set
the visibility of each component.
http://zevolving.com/2012/01/abstract-class-vs-interface/
Overriding:
Overriding is useful, when we want to extend the functionality of the inherited method. Static
methods cannot be redefined.
Inheritance
Inheritance allows you to derive a new class from an existing class. You do this using the
INHERITING FROM addition in the
In rare cases, however, classes have to work so closely together that they require access to each
others' protected or private components. The concept of friendship between classes has been
developed so that these components do not need to be made available to all users at the same
time.
Friends
A class can grant friendship to other classes and interfaces (and thus to all classes that
implement this interface). To create this relationship, use the FRIENDS additions of the CLASS ...
DEFINITION statement that includes all classes and interfaces to which you want to grant
friendship. These friends are granted access to the protected and private components of the
class granting the friendship and can always generate instances of this class, independently of
the CREATE addition of the CLASS statement.
Important points:
To use protected method of a super class we can make a public method in sub class and
then we can use the protected method in subclass.
Every time a subclass is accessed then the class-constructor of super class is accessed
first then class constructor of sub class.