Pages

Thursday, 24 July 2014

OOPS meterial in AX 2012 and 2009


1.Class]]
2.Object]]
3.Inheritance]]
4.Polymorphism]]
5.Encapsulation]]

In Dynamics AX, objects are usually created in the base class using a static method called ‘construct'. The construct method usually accepts parameters like table buffers or other types of variables. The construct method acts like an object factory 'producing' objects depending on the input parameters.

You might be asking yourself if isn’t it easier to put all the code in one place? That might be the case if you want to produce code in a hurry. Rest assured, this approach might be faster but it is certainly not better. The reason is simple: if code is written in an unstructured manner, finding and solving bugs is more difficult and quite often results in code that is broken in one place when fixing it in another place. This can also occur when using OOP except that it very easy to avoid if the programmer is aware of this.

This is one of the many pitfalls that OOP helps to solve. With OOP, the code pertaining to a specific purpose is encapsulated in its own class. This means maintaining the code can be done in a specific class only. If the code is changed in a class, sibling classes are not affected but children classes are. If desired, it is simple to propagate code changes to all child classes by changing the code in a single place, the base class. All child classes will automatically inherit the new code.

 1. Class:
In object-oriented programming a class is a programming language construct that contains properties and methods. The properties represent the attributes of an object and the methods represent the actions that an object can perform. A common design pattern is to have a parent class and child classes that specialize the methods of the parent class.

2. Object.

In object-oriented programming an object is an instance of a class   and is created using the new operator. In Dynamics AX a commonly used pattern is the factory method using a static construct method.

3.Inheritance.
In object-oriented programming inheritance means that a class  can inherit properties and methods from another class. This is a powerful feature because code changes in the parent class are propagated to all child classes. The advantage of that is that code only has to be changed in the parent class for the all the child classes to benefit from it.

4.Polymorphism.
Polymorphism is a core concept in oop and goes hand in hand with Inheritance. You can use an object from type of a subclass always like an object from type of a superclass. By example if you create a class that extends RunBaseBatch you can use it always like a RunBaseBatch Object.

 5.Encapsulation.
In object-oriented programming encapsulation means that code that logically belongs together is placed in a single entity, namely a class. Accessing code and modifying class variables is achieved by using public class methods.

No comments:

Post a Comment