will be glad to know the comments from you.
The Ducks are back duplicating here for your conveniance.
Why do we need abstract class???:-
1) Go thr' all the API list and
"study" the abstract classes.
OK, i will walk you through. Here we go...Consider the AbstractCollection, abstract class.
There are only 2 methods that are defined abstract namely
1)int size() and
2) Iterator iterator().
think for a second(preferably 2/3 days), why these implementations are delegated to the child classes.
Ok, i will do it for you.
1)take size(), how to define it???
one way is,
the sum of elements in a collection.
Why not implement it in Abstract Class???
========================================
what if there is a criteria (implementation), wherein you want to ignore nulls/duplicates etc. looking from the AbstractCollection view, size can't be concretely implemented.
one implementaion of size() might be:-
1) getArray().length()
2) getArray()
//remove duplicates then return size
3) getArray()
//remove nulls then return size etc..
4)
consider iterator() implementaion
1) return Array.toList(getArray()).itetrator()
2) you got it.........
But what is the beauty of an Abstract class??. please check the following implementation[maybe] of sun's AbstractColllection
Summary:-
1) The abstract methods are a way to say "if you answer me a question aka method [note the anwer varies], then i will answer/solve some other question".
2) the parent is having lot of "hooks". the parent's concrete methods [not all methods] will depend on the hooks to solve some general stuff!!
like "if you say what's your size, then i will tell you whether you are empty"
3) An Abstract class is like a counsellor.
the "hook" can be placed anywhere in the general flow(any method) so that it gives a uniform implementation to all other concrete methods.
To give an real time example, imagine you are going to get the blessing from a Priest. The priest expects that you confess your sins before the blessing.[whether you really confess is another story
] . According to the contract of a Priest,read the soliloquy
"When anyone seeks my blessing, i will ask my self to confessSin, to purify my heart,i don't know how the confessSin would be ... it depends on the Priest and the religion.
different form of confessSin would be:-
1)removing some blood from the body
2)shouting from the roof top
3)praying to God
4)telling what kind of beast you are to the Person who asks the blessing.
Look at the flow above. i am plugging the confessSin() inside the getBlessing(). I can also plug-in the confessSin() before resignJob() or takeJob() or whatever . the point is that, some changable implementation is put inside the generic flow.
Hope this is of help! Looking for comments and appreciations