• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Different methods of extending vs reusability

 
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does extending by sub-classing , delegation etc make for less re-usability of the system ?Re-usability is kind of a Holy Grail to most developers.
regards
[ September 13, 2003: Message edited by: HS Thomas ]
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://members.hknet.com/~hermanxmz/ouhk/mt356/herman2002/unit2/ar01s08s06.html
 
HS Thomas
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Delegation vs inheritance
Those are both ways of extending, are they not ?
regards
[ September 11, 2003: Message edited by: HS Thomas ]
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by HS Thomas:
Does extending by sub-classing , delegation etc make for less re-usability of the system ?


How do you reuse if not by either subclassing or delegating?
 
HS Thomas
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What I mean is that the more you extend the less likely that the code will get re-used. Extension can lead to an explosion of code.
Build standard class libraries first. Really understanding the existing code-base first before starting to write any code and try to cut down on having to refactor.
I am talking against rampant extensions (which call for excessive refactorings).
In one place I worked in ,over the standard Java libraries there was a project-specific class hierarchy about two levels deep (if that) which I think led to non-reusable procedural code.[ BTW I did point out repeatedly that there was no OO Design and suggested they get an OO mentor]
OO Design was not a strongly enforced and I suspect that rampant extensions without refactorings would follow as the project grew.
regards
Is this making any sense to anyone ?
[ September 14, 2003: Message edited by: HS Thomas ]
 
HS Thomas
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This question may be more pattern-orientated.
Pradeep and Illja ,you were right that extension IS the form of re-use for ordinary classes. What about adding behaviour to collections of classes ? Sometimes you may want to add this behaviour dynamically to an object without altering the object's class.
So you'd use an appropriate pattern as an extension.
Obvious,huh? Sorry if I have confused anyone.
regards
[ September 12, 2003: Message edited by: HS Thomas ]
 
Pradeep bhatt
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

So you'd use an appropriate pattern as an extension.


I think there is a pattern for this one.
 
HS Thomas
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are several extension patterns, depending on the problem-solution, . Template, Command, Iterator to name a few.
How is this good reuse rather than extending classes the usual way?
I suppose it means you can code a single Iterator Pattern to be used with several Collection classes ,to do something project specific. I think that the Voyager Pattern Discovery should look for existing solutions before coding your own.
What do you all think? And how would you manage that? If you find yourself designing/coding an Iterator think how it could be made useful to others and place it somewhere they can reuse it.
regards
BTW that seems a good link, Pradeep.
[ September 12, 2003: Message edited by: HS Thomas ]
 
Pradeep bhatt
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
www.javaworld.com/javaworld/jw-08-2003/ jw-0801-toolbox.html?post=677&lastpage=1
 
HS Thomas
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Extends is evil
Is this the link you mean ?
regards
 
HS Thomas
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seriously , shouldn't there be an effort to strive for as small a code- base as possible? By making an effort to design reusable code ?
regards
[ September 12, 2003: Message edited by: HS Thomas ]
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Seriously , shouldn't there be an effort to strive for as small a code- base as possible? By making an effort to design reusable code ?


That's called "refactoring"... Refactoring theoretically produces the smallest codebase possible by reducing redundant code.
In general, I would say that reusable code almost always produces a larger codebase than code that is tuned to a specific application. Remember that in order to reuse you need to generalize the component (which, in turn means more code to accomodate the new usage scenarios' needs).
 
HS Thomas
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where does refactoring fit/balance with design then?
Here's my take given what you've said:
Refactoring is mainly designing from code (perhaps a little UML).
Design is the activity done with UML models.
Refactoring achieves smaller code bases.
Design explores and is code expansive.
That makes sense.
regards
[ September 13, 2003: Message edited by: HS Thomas ]
 
HS Thomas
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Lasse Kossekela:
Remember that in order to reuse you need to generalize the component (which, in turn means more code to accomodate the new usage scenarios' needs).


Can't that be done as new usage scenarios are discovered?
There must be degrees of reuse, the highest being components,middling being design patterns and the smallest objects - and others in between.
regards
[ September 13, 2003: Message edited by: HS Thomas ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic