Sunday, June 24, 2007

Interface - Where and When?

I understand that if I use interface, my application can a high flexible construction. I can easily extend class to add more function, and also make use of strong point of polymorphism and dynamic binding. But I'm wondering that where and when I should use interface.

At this time I'm developing a small application it contains a Tourist class and I can't imagine that when I need to create some more specific kinds of Tourist. Even I need to extend Tourist, I can re-factor Tourist to be a abstract class (or keep it unchanged) and then create subclasses of Tourist. Where is the place I need to consider to use interface here?

As I told you, I'm developing a small application and I know it still keep in small level, hardly to become bigger. So what is the matter I need to use interface here? That is WHEN question.

What do you think about the WHERE and WHEN?

1 comment:

t800t8 said...

The answer for both WHERE and WHEN questions is you need to use interfaces WHERE and WHEN:
+ you want to create a weak is-a relationship (or is-kind-of relationship), and/or
+ you need multiple inheritance.