Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Beginner inheritance Question.

Status
Not open for further replies.

borntorun

MIS
Oct 16, 2003
82
GB
Ok i know you java gurus gringe whenever you see the beginners question in a title.

Ok I understand the difference between extending interfaces and implementing classes the differences between overriding/overloading.

My question is, you can overload and i think over-ride any method that can be found by searching in the class path, and use that method in your class, obviously assuming it is correctly referenced in the class.

So when do you decide to extend a whole class or implement an interface or just use one method in your class. Are there any reasons not to the majority of the time just use the method. It seems to me early on in designing your application you will want to extend classes and implement interfaces as you are defining the structure of your program later on, or when the application is developed and you are playing with it testing it and then you will only want to use certain methods. Anything obvious i have missed here in this assumption.

Thanks guys.
 
Let me give you an example for those.In accounting we have various document such as invoices,cheques,bank refunds etc. what are these?These are "documents".Why are they called as "documents" because
documents have a certain date,number,company names,description etc. So it is logical to create a Document class that have these common properties.So the specialized document extend this Document so they inherit the Document's properties.

Now ... These specialized documents should be transfered into company accounts don't they?)(unless you are illegal trafficking [smile]) All of these specialized documents MUST BE transfered.But they are transfered differently.Bank accounts are written as debt of bank,invoices are written as company accounts etc. But they must be in a certain discipline.Since a document MUST BE transfered;it is useful to create a AccountancyRule interface and this interface must have a transfer method.And your documents will implement this Rule class and you are to develop your method in that classes.
After the end of day; there will be many documents to be transfered.But you can give orders to transfer all of the documents in a loop and the method will find your correct methods. That will create efficiency in your work.
That is a way to use Interfaces and super classes

Salih Sipahi
Software Engineer.
City of Istanbul Turkey
s.sipahi@sahinlerholding.com.tr
turkey_clr.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top