Posts

Showing posts from November, 2012

Abstraction in OOPs

Image
Abstraction in OOPs Abstraction  in  Object Oriented Programming  helps to hide the irrelevant details of an object.  Abstraction  is separating the functions and properties that logically can be separated to a separate entity which the main type depends on. This kind of  Abstraction  helps in separating the members that change frequently. Abstraction is one of the key principles of the  OOAD (Object oriented analysis and Design). Applying  Abstraction  during the design and domain modeling, helps a lot in design the a system which is flexible and maintainable. Abstraction is achieved by Composition. Abstraction Example: A Car has Engine, wheels and many other parts. When we write all the properties of the Car, Engine, and wheel in a single class, it would look this way: public class  Car  {         int  price;      String name;      String color;      int  engineCapacity;      int  engineHorsePower;           String wheelName;      int  wheelPrice;           vo

Encapsulation in Object Oriented Programming

Image
Encapsulation in Object Oriented Programming Encapsulation is one of the four fundamentals of the Object oriented programming. What is Encapsulation? Encapsulation is a language mechanism to restrict the access of the Objects components to other Objects or Classes.  Encapsulation helps in enforcing the security of the data related to a particular object. In the programming models like Structural, procedural and Modular programming, there was not much provision to safeguard the data from the other procedures or functions. This can lead to the misuse of data or even the design by responsibility principle of OOAD can be some times breached. Every Object in Object oriented programming has full control of what members(Fields and methods) to be accessible to its peers in a package, outside the package and should only be visible to its own members alone. Encapsulation in Object Oriented Programming is implemented by mentioning the Access Modifiers like public, protected, privat

Inheritance in OOPs.!

Image
Inheritance in OOPs Inheritance is a very important feature in object oriented programming. Inheritance is extremely useful in enabling the  re-usability  of the code and is enabled by using the  extends  keyword. Inheritance and its advantages Just like a child inherits some behaviors from their parents, Objects in the programs also get some methods and properties from their parent classes. Inheritance helps  to access the basic functionality already declared in the parent types and gives an opportunity to declare new functionality in the sub types. This gives the child an opportunity to declare some new methods and properties in it and still be able to have access to its super classes methods and properties through its instances. Please note that  there is no multiple inheritance in Java.  A class can extend only one class. One has to consider using interfaces to add more functionality. Let me explain  Inheritance with an example . Consider we have a type called