Email Subscriptions

Enter your email address:

Delivered by FeedBurner

Sunday, January 24, 2010

Tips...

when d u want to use and interface and when u want to use an abstract class while designing classes?

Abstract classes: When you want to model the homogeneous objects use an abstract class to phase out in abstract class common data constants or variables and behavior.
Restrictions can be placed via abstract class on inheriting classes.

Interface: When you got to model heterogeneous objects then common constants you might want to phase out, or providing .

to be edited.....


-------------------------------------------------

pie

polymorphism, inheritance and encapsulation.


The ‘is a’ relationship is expressed with inheritance and ‘has a’ relationship is expressed with composition.

Which one to use? The guide is that inheritance should be only used when subclass ‘is a’ superclass.

�� Don’t use inheritance just to get code reuse. If there is no ‘is a’ relationship then use composition for code reuse. Overuse of implementation inheritance (uses the “extends” key word) can break all the subclasses, if the superclass is modified.
�� Do not use inheritance just to get polymorphism. If there is no ‘is a’ relationship and all you want is polymorphism then use interface inheritance with composition, which gives you code reuse (Refer Q8 in Java section for interface inheritance).


What is the difference between aggregation and composition?
Aggregation Composition: Aggregation is an association in which one class
belongs to a collection. This is a part of a whole relationship where a part can exist without a whole.For example a line item is a whole and product is a
part. If a line item is deleted then corresponding product need not be deleted. So aggregation has a weaker relationship.

Composition is an association in which one class belongs to a
collection. This is a part of a whole relationship where a part
cannot exist without a whole. If a whole is deleted then all parts are
deleted. For example An order is a whole and line items are parts.
If an order deleted then all corresponding line items for that order
should be deleted. So composition has a stronger relationship.