By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,105 Members | 1,508 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,105 IT Pros & Developers. It's quick & easy.

Design Question Interface

P: n/a
Hi
I do have an Interface, which is implemented in lot of places, My
question is i observed that After quite some time if i need to add a
new method in the interface , i need to do a lot of rework in lot of
places , So i do see a flaw in my design, How best we can avoid this
situation

Thanks in Advance

thomson

May 10 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a

"thomson" <sa**********@yahoo.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com...
Hi
I do have an Interface, which is implemented in lot of places, My
question is i observed that After quite some time if i need to add a
new method in the interface , i need to do a lot of rework in lot of
places , So i do see a flaw in my design, How best we can avoid this
situation


The basic idea with interfaces is not to change them but to define a new
interface.

This is why some people prefer to use base classes wherever possible - it is
easier to update. However there are drawbacks with that approach too.
May 10 '06 #2

P: n/a
"thomson" <sa**********@yahoo.com> wrote:
I do have an Interface, which is implemented in lot of places, My
question is i observed that After quite some time if i need to add a
new method in the interface , i need to do a lot of rework in lot of
places , So i do see a flaw in my design, How best we can avoid this
situation


The recommended approach is to use an abstract base class instead. They
version better. If you need to add a new method in the future, you can
implement it in terms of existing methods, or implement some kind of
default.

Interfaces work best for fine-grained behaviour that needs to be
supported by arbitrary classes, irrelevant of where they are in an
existing hierarchy.

Check out section 4.3 of the Framework Design Guidelines book by Cwalina
and Abrams, it has a good discussion of this.

-- Barry
May 10 '06 #3

P: n/a
Can you let me know how would be the implentation of abstract base
class in this scenario, and please let me know the flaws of abstract
class design

May 10 '06 #4

P: n/a
Hi,

"thomson" <sa**********@yahoo.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com...
Hi
I do have an Interface, which is implemented in lot of places, My
question is i observed that After quite some time if i need to add a
new method in the interface , i need to do a lot of rework in lot of
places , So i do see a flaw in my design, How best we can avoid this
situation

You could say it's a flaw, you could also say it was an unforeseen
requirement. it does not matter now really.

You have two possible paths:

1- Modify the interface, this mean modify ALL the classes that implement it.
IF you have access to all these code and the implementation is similar in
all (or most) of the cases you could go out and modify all the classes.

2- Define an interface derived from the original one that define the new
member needed. then you can modify (or derive ) the classes that need to
implement it.

Unfortunately I do not see other way to solve your situation.

out of curiosity, does the new method needs extra member variables ?

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

May 10 '06 #5

P: n/a
"thomson" <sa**********@yahoo.com> wrote:
Can you let me know how would be the implentation of abstract base
class in this scenario
Stream, TextReader and TextWriter are all examples of these abstract
base classes. Compare their design and place in their hierarchies with
your own.
please let me know the flaws of abstract
class design


The only problem with using an abstract class instead of an interface is
that you can't then bolt it onto an existing class hierarchy.

In the book I mentioned, Rico Mariani suggests this:

"Good interface candidates often have this 'mix-in' feel to them. All
sorts of objects can be IFormattable -- it isn't restricted to a certain
subtype. It's more like a type attribute."

-- Barry
May 10 '06 #6

P: n/a

"Barry Kelly" <ba***********@gmail.com> wrote in message
news:1m********************************@4ax.com...
"thomson" <sa**********@yahoo.com> wrote:
Can you let me know how would be the implentation of abstract base
class in this scenario


Stream, TextReader and TextWriter are all examples of these abstract
base classes. Compare their design and place in their hierarchies with
your own.
please let me know the flaws of abstract
class design


The only problem with using an abstract class instead of an interface is
that you can't then bolt it onto an existing class hierarchy.


Somewhere in the MS library guidelines it explicitly mentions that they use
abstract base classes as a matter of policy because they don't have the
backward compatibility problems of interfaces.... but then they never have
to fit into someone else's hierarchy :(

May 10 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.