OOPs Concepts:
Object-Oriented Programming (OOP) uses a different set of programming languages than old procedural programming languages (C, Pascal, etc.). Everything in OOP is grouped as self-sustainable "objects".
In order to clearly understand the object orientation, let’s take your “hand” as an example. The “hand” is a class. Your body has two objects of type hand, named left hand and right hand. Their main functions are controlled/ managed by a set of electrical signals sent through your shoulders (through an interface). So the shoulder is an interface which your body uses to interact with your hands. The hand is a well architected class. The hand is being re-used to create the left hand and the right hand by slightly changing the properties of it.

Object:
An object can be considered a "thing" that can perform a set of related activities. The set of activities that the object performs defines the object's behavior. For example, the hand can be used to write, to hit and to grip something, etc.





Class:
A class is simply a representation of a type of object. It is the blueprint/ plan/ template that describe the details of an object. A class is the blueprint from which the individual objects are created. Class is composed of three things: a name, attributes, and operations.
In simpler words, it is a type of user defined data type.
For example:




For a class we can create number of objects depending on our requirements.




The object oriented programming is based on objects and classes and it gains strength through four main object-oriented programming concepts.
They are:

Abstraction:
An abstraction is a model of a complex system that includes only the essential details. Different viewers use different abstractions of a particular system.
Example:


Thus, while we see a car as a means of transportation, the automotive engineer may see it as a large mass with a small contact area between it and the road.
Properties of the object are exposed only to an extent to which the user of the object need to know to use it.

Encapsulation:
The encapsulation is the inclusion within a program object of all the resources need for the object to function - basically, the methods and the data. In OOP the encapsulation is mainly achieved by creating classes, the classes expose public methods and properties. The class is a kind of a container or capsule or a cell, which encapsulate the set of methods, attribute and properties to provide its indented functionalities to other classes. Encapsulation is needed to hide how a class does the functionality without letting it know to the external environment how it is happening.
Example,







In the above example, the properties is protected by the class and restricts them for unauthorized access.

The difference between encapsulation and abstraction can be understood with the image below.

Inheritance:
Ability of a new class to be created, from an existing class by extending it properties, is called inheritance. In OOPs, the keyword extends specifies that the given class is inheriting another class by extending its properties and methods.




For Example,


Here, Car is a Super class with properties color, horsepower and number of seats. The child class Racecar is extending Car by adding nitro property in it and the child class Truck extending Car by adding trailer property in it.

Polymorphism:
Polymorphisms is a generic term that means 'many shapes'. More precisely Polymorphism means the ability to request that the same operations be performed by a wide range of different types of things.

For Example,



Here, speak () is a method which is in the Animal Class. When you call speak() method, depending on the object(in this case, it can be a cat, dog, duck) it is pointing to, the method in that particular object will gets executed.
We usually think of classes as being complete definitions. However, there are situations where incomplete definitions are useful, and classes that represent these incomplete definitions are equally useful and they are called Abstract Class. Abstract classes, which declared with the abstract keyword, cannot be instantiated (Note: Instantiation of a class is the creation of a new instance of that class). It can only be used as a super-class for other classes that extend the abstract class. Abstract class is the concept and implementation gets completed when it is being extended by a subclass. In addition to this, a class can inherit only from one abstract class (but a class may implement many interfaces) and must override all its abstract methods/ properties.
For example,

abstract class Bike 
{ 
 int limit=30; 
 Bike()
{
System.out.println("constructor is invoked");
} 
            void getDetails()
{
            System.out.println("it has two wheels");
} 
            abstract void run(); 
} 
class Honda extends Bike
{ 
 void run()
{
            System.out.println("running safely..");
} 
            public static void main(String args[])
{ 
Bike obj = new Honda(); 
            obj.run(); 
obj.getDetails(); 
System.out.println(obj.limit); 
            }
} 
Interface:
An interface is not altogether a new one for us; just it is a special flavor of abstract class where all methods are abstract. That is, an interface contains only abstract methods (methods with empty bodies). The Interface separates the implementation and defines the structure, and this concept is very useful in cases where you need the implementation to be interchangeable. Apart from that an interface is very useful when the implementation changes frequently. Interface can inherit other interface.



In OOPs, the keyword implements specifies that the given class implements an interface.


Function Overloading:
Overloading is where there is more than one method with the same name, but the methods have different signatures (return type or parameter lists or both).

class Calculation
{  
void sum(int a,int b)
{
System.out.println(a+b);
}  
void sum(int a,int b,int c)
{
System.out.println(a+b+c);
            }

  
public static void main(String args[])
{  
Calculation obj=new Calculation();  
obj.sum(10,10,10);  
obj.sum(20,20);  
}
}  


Function Overriding:

Overriding is where the superclass's implementation of a method is altered by the subclass's implementation of the method, but the signatures of both methods are the same.

// Superclass: Attribute
public class Attribute
{
    int objectVariable;
}
void methodAtt()
{
    //Some statements
}

// Subclass: ColorAttribute
public class ColorAttribute extends Attribute
{
    int addedObjectVariable;
}
void methodAtt()
{
    //Some statements
}

X++ supports overriding, but it does not support overloading.

Access specifier:

The access modifiers specifies accessibility (scope) of a data member, method, constructor or class. They are:

1) private:
The private access modifier is accessible only within class.

2) protected:
The protected access modifier is accessible within package and outside the package but through inheritance only.

3) public:
The public access modifier is accessible everywhere. It has the widest scope among all other modifiers.

Comments

Popular posts from this blog

Create RFQ through X++

Base enum values in Dynamics 365

Project Id through X++ code