Abstract Base classes - [op john gagon]

J

John Gagon

I'm wondering if there should ever be inheritance instead of
composition. Can you get away with never using extends and just use
field members. I understand that one can use this as an "is a"
relationship but I think interfaces, having multiples of them allowed
are more appropriate.

Some say that one should use a base class if therre is shared
functionality. I've seen it used very usefully for "deferred"
functionality sometimes but I'm still wondering if that can be done by
composition too. What I mean by deferred is that an abstract class's
non-abstract methods calling abstract ones. With composition, it seems
you'd have the enclosing class merely call the method passing in what
it would need and delegating but somehow, it doesn't seem to fit as
well. I thought perhaps "decorator" and lazy instantiation might be
useful or maybe even listener-/action/event model. This all seems a bit
fuzzy and decorators seem rather powerful but also a bit obscure since
the order of nesting seems so arbitrary. Is there a way to control that
with the pattern better?

Thank you.



John Gagon
---
Disclaimer:
All content posted here is the property of John Gagon by virtue of
declaration. John Gagon may revoke this right at any time only via a
formal declaration by John Gagon. If you disagree with John Gagon, keep
in mind that words are not always the things. Everything is relative
and possibly metaphorical. In the event you disagree, it will
automatically be classified as "taken out of context" after which John
Gagon will explain to you the actual context which should clear
everything with formal definitions that will be agreed upon by John
Gagon.
 
L

LordAlfredHenry

John Gagon wrote something John Gagon's mother would be ashamed of:
I'm wondering if there should ever be inheritance instead of
composition. Can you get away with never using extends and just use
field members. I understand that one can use this as an "is a"
relationship but I think interfaces, having multiples of them allowed
are more appropriate.

Some say that one should use a base class if therre is shared
functionality. I've seen it used very usefully for "deferred"
functionality sometimes but I'm still wondering if that can be done by
composition too. What I mean by deferred is that an abstract class's
non-abstract methods calling abstract ones. With composition, it seems
you'd have the enclosing class merely call the method passing in what
it would need and delegating but somehow, it doesn't seem to fit as
well. I thought perhaps "decorator" and lazy instantiation might be
useful or maybe even listener-/action/event model. This all seems a bit
fuzzy and decorators seem rather powerful but also a bit obscure since
the order of nesting seems so arbitrary. Is there a way to control that
with the pattern better?

Thank you.

Hey there, you know, I think it can be useful when there is a very
minor difference or you want to prevent instantiation or preinstantiate
certain values across a bunch of different classes, and as you say,
defer implementation.

LAH.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top