Re: interface vs. inheritance
From: Jeff Louie (jeff_louie_at_yahoo.com)
Date: 02/08/05
- Next message: Craig: "RE: Can't change cursor within a control"
- Previous message: D: "RegEx how do I do unique?"
- In reply to: Hazz: "interface vs. inheritance"
- Next in thread: Hazz: "Re: interface vs. inheritance"
- Reply: Hazz: "Re: interface vs. inheritance"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 08 Feb 2005 13:48:48 -0800
1)Favor containment.
2)Avoid extending a class unless it was designed to be extended.
3)If you have a well defined contract that will be implemented by many
classes use an interface. An interface represents a purely abstract IS_A
relationship.
4)If the contract is evolving, consider using a base class so that you
can provide default implementations of any new methods so that clients
that use your base class can be recompiled without breaking.
5)Use a base class if you need to include implementation details.
That said... every time I try to solve a problem I seem to start by
describing the contract with an interface say IVersionable. Then I end
up writing an abstract class with default implementations as in
AbstractVersion. Then I end up creating concrete classes based on the
Abstract class as in Version : AbstractVersion.
So I would try this pattern: Interface -- AbstractInterface -- Class
which uses both interfaces and base classes and offers both options to
the user of the "interface/class."
Regards,
Jeff
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
- Next message: Craig: "RE: Can't change cursor within a control"
- Previous message: D: "RegEx how do I do unique?"
- In reply to: Hazz: "interface vs. inheritance"
- Next in thread: Hazz: "Re: interface vs. inheritance"
- Reply: Hazz: "Re: interface vs. inheritance"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|