Wednesday, 9 July 2014

OOPS

1. The Object Oriented Programming Languages directly represent the real life objects like Car,Account,Customer etc. The features of the OO programming languages like polymorphism, inheritance and encapsulation (PIE) make it powerful.
2. The key benefits of OOPS are:


  • Re-use of previous work: using implementation inheritance and object composition.
  • Real mapping to the problem domain: Objects map to real world and represent vehicles, customers, products etc: with encapsulation.
  • Modular Architecture: Objects, systems, frameworks etc are the building blocks of larger systems.

The increased quality and reduced development time are the by-products of the key benefits discussed above.
3. Inheritance("is-a) relationship is UniDirectional. Eg :  House is a Building but Building is not a house.
4. Composition is "has-a" relationship. Eg: House has a bathroom.
5. Problem with class inheritance is that the subclass becomes dependent on the parent class implementation.
This makes it harder to reuse the subclass, especially if part of the inherited implementation is no longer desirable and hence can break encapsulation. Also a change to a superclass can not only ripple down the inheritance hierarchy to subclasses, but can also ripple out to code that uses just the subclasses making the design fragile by tightly coupling the subclasses with the super class. But it is easier to change the interface/implementation of the composed class.
6. Encapsulation – refers to keeping all the related members (variables and methods) together in an object. Specifying member variables as private can hide the variables and methods. Objects should hide their inner workings from the outside view. Good encapsulation improves code modularity by preventing objects interacting with each other in an unexpected way, which in turn makes future development and refactoring efforts easy.

7. Abstract classes let you define some default behavior and force subclasses to provide any specific behavior.
8. Overloading deals with multiple methods in the same class with the same name but different method signatures. Overloading lets you define the same operation in different ways for different data.
9. Overriding deals with two methods, one in the parent class and the other one in the child class and has the same name and  signatures. Overriding lets you define the same operation in different ways for different object types.
10. Serialization is a process of reading or writing an object. It is a process of saving an object’s state to a sequence of bytes, as well as a process of rebuilding those bytes back into a live object at some future time.
common use of serialization is to use it to send an object over the network or if the state of an object needs to be persisted to a flat file or a database.
11. Polymorphism: The same message sent to different objects, results in behavior that is dependent on the nature of the object receiving the message.
12. Abstraction : is the process where ideas are distanced from the concrete implementation of the objects. The concrete implementation will change but the abstract layer will remain the same.
Let us look at an analogy:
When you drive your car you do not have to be concerned with the exact internal working of your car (unless you are a mechanic). What you are concerned with is interacting with your car via its interfaces like steering wheel, brake pedal, accelerator pedal etc. Over the years a car’s engine has improved a lot but its basic interface has not changed (i.e. you still use steering wheel, brake pedal, accelerator pedal etc to interact with your car). This means that the implementation has changed over the years but the interface remains the same. Hence the knowledge you have of your car is abstract.

13. Loose coupling: The process of making objects independent of each other rather than dependent of one another.Loosely coupled objects are easier to reuse and change.
14. A class which declares or inherits a virtual function is called a polymorphic class 


No comments:

Post a Comment