OOP Properties by G Krishna Chauhan

4 major principles of Object-Oriented Programming :

For you new programmers or programmers new to OOP, this article will briefly explain the 4 major principles that make a language object-oriented: Encapsulation, Data Abstraction, Polymorphism and Inheritence. All examples will be in VB.Net,because in my opinion its easier for a new OOP programmer to read andunderstand at first. Certainly don’t think I’m saying you should use one .Net based language over another, as they all are based on the CLR/CLS and all end up as the same assembly language when compiled. Its your preference that determines what language you use.  Of course, there are other OOP languages out there, such as Ruby, a pure OOP language, and hybrid languages such as Python, C++ and Java to mention a few. 


  • Encapsulation
  • Abstraction
  • Inheritance
  • Polymorphism



Encapsulation:


Encapsulation is one of the four fundamental OOP concepts. The other three are inheritance, polymorphism, and abstraction.


Encapsulation is the technique of making the fields in a class private and providing access to the 
fields via public methods. If a field is declared private, it cannot be accessed by anyone outside the class, thereby hiding the fields within the class. For this reason, encapsulation is also referred to as data hiding.



Encapsulation can be described as a protective barrier that prevents the code and data being randomly accessed by other code defined outside the class. Access to the data and code is tightly controlled by an interface.



The main benefit of encapsulation is the ability to modify our implemented code without breaking the code of others who use our code. With this feature Encapsulation gives maintainability, flexibility and extensibility to our code.



To bind up diffrent difrent data members of functions in a single unit i.e. class . This is encapsulation "



Abstraction:


Data abstraction is the simplest of principles to understand. Data abstraction and encapuslation are closely tied together, because a simple definition of data abstraction is the development of classes, objects, types in terms of their interfaces and functionality, instead
of their implementation details. Abstraction denotes a model, a view,or some other focused representation for an actual item. Its the development of a software object to represent an object we can find in the real world. Encapsulation hides the details of that implementation.
Abstraction is used to manage complexity. Software developers use abstraction to decompose complex systems into smaller components. 


The best definition of abstraction I’ve ever read is: “An abstraction denotes

the essential characteristics of an object that distinguish it from all other kinds of object and thus provide crisply defined conceptual boundaries, relative to the perspective of the viewer.” — G. Booch .


Other defination:

"We can hide the complacity of the program  .This phenomenon known as Abstraction ." — G. Krishna Chauhan.


Lavels on which we can hide complacity  are as followes :

1.Physical 
2.Logical
3.View



Inheritance:



Now lets discuss inheritance.  Objects can relate to eachother with either a “has a”, “uses a” or an “is a” relationship.  “Is a” is the inheritance way of object relationship.  The example of

this that has always stuck with me over the years is a library.  So, take a library, for example.  A library lends more than just books, it also lends magazines, audiocassettes and microfilm.  On some level, all of these items can be treated the same: All four types represent assets of the library that can be loaned out to people. However, even though the 4 types can be viewed as the same, they are not identical.  A book has an ISBN and a magazine does not. And audiocassette has a play length and microfilm cannot be checked out overnight.

Each of these library’s assets should be represented by its own class definition.  Without inheritance though, each class must independently implement the characteristics that are common to all loanable assets.  All assets are either checked out or available for checkout.  All assets have a title, a date of acquisition and a replacement cost.  Rather than duplicate functionality, inheritance allows you to inherit functionality from another class, called a superclass or base class.


Types :


1. Single lvel
2. Multy lavel
3. Herarical lavel
4. Hibrid lavel


Polymorphism:


Polymorphism means one name, many forms.  Polymorphism manifests itself by having multiple methods all with the same name, but slighty different functionality.  Many VB6ers are familiar with interface polymorphism.  I’m only going to discuss polymorphism from the point of view of inheritance because this is the part that is new to many people.  Because of this, it can be difficult to fully grasp the full potential of polymorphism until you get some practice with it and see exactly what happens under different scenarios.  We’re only going to talk about polymorphism, like the other topics, at the basic level. 


There are 2 basic types of polymorphism.  Overridding, also called run-time polymorphism, and overloading, which is referred to as compile-time polymorphism.  This difference is, for method overloading, the compiler determines which method will be executed, and this decision is made when the code gets compiled. Which method will be used for method overriding is determined at runtime based on the dynamic type of an object.

No comments:

Post a Comment