Re: Basic Concept Question Why Interface?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Nick Malik (nickmalik_at_hotmail.nospam.com)
Date: 06/15/04


Date: Tue, 15 Jun 2004 02:54:58 GMT

The answer can be found by digging deeper into Design Patterns.

Consider: http://home.earthlink.net/~huston2/dp/patterns.html
(just one of thousands of links about design patterns, although Vince Huston
is a bit more "convinced" than most folks. I like the site for its
tutorials).

If you drill into each of the design patterns under the Gang-of-Four
section, you will begin to notice two things:

1) These are EXCELLENT solutions to some really common problems, (ranging
from simple to really difficult problems). If you really take the time to
learn these patterns, your programming will improve dramatically, and

2) Nearly every one of these design patterns REQUIRES the use of interface
definitions in order to create the concept of a contract where any object
that implements the contract can be substituted for any other object that
also implements the contract. (this ability to substitute forms the
implementation foundation of the Liskov Substitution Principle).

In other words, delve deeper. Keep asking questions. Pick up a copy of
"Design Patterns Explained" by Alan Shalloway and James Trott. Then read
it. Then read it again.

And enjoy this journey... it's a fun ride.
--- Nick

"jm" <john_20_28_2000@yahoo.com> wrote in message
news:c67e4bdd.0406141337.10d9ec47@posting.google.com...
> Consider:
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbconwhenshouldiimplementinterfacesinmycomponent.asp
>
>
> // Code for the IAccount interface module.
> public interface IAccount
> {
> void PostInterest();
> void DeductFees(IFeeSchedule feeSchedule);
> }
> class BusinessAccount : IAccount
> {
> void IAccount.PostInterest()
> {
> // Code to post interest using the most favorable rate.
> }
>
> void IAccount.DeductFees(IFeeSchedule feeSchedule)
> {
> // Code to change a preferred rate for various services.
> }
> }
>
>
> Note An interface is a contract. You must implement all of the
> properties and methods in the interface.
>
> I do not understand why Interface was necessary. Why not just have
> the class BusinessAccount and two functions in it PostInterest() and
> DeductFees()?
>
> Thank you.



Relevant Pages

  • Re: how to refernce a folder?
    ... sometimes the best thing to do is attempt to follow the advice and see what happens. ... All advice, strategies, design patterns, etc. in programming are intended to make things _easier_. ... The interface should be general purpose. ... In programming generally, not just OOP, not just MVC, MVP, etc. it is useful to keep in mind the different between API or "interface" and implementation. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Class inheritence & subclassing
    ... Provides a common interface for accessing containers and objects. ... The Design Patterns book is a must-have for OO developers - problem is ... ' IColoredComponent ... Public ReadOnly Property Color() As System.Drawing.Color Implements ...
    (microsoft.public.dotnet.languages.vb)
  • Re: a java design question
    ... > functions as long as they implement the interface and so I dont have to ... > int a; ... instantiating objects is not that expensive. ... using known design patterns enhances the ...
    (comp.lang.java.help)
  • Re: Program to an Interface not an implemetation
    ... >I am looking at the Gang of Four ... > an Interface, not an implementation'. ... book like "Design Patterns Explained" by Shalloway. ... I do not answer questions on behalf of my employer. ...
    (comp.object)
  • Re: Basic Concept Question Why Interface?
    ... >The answer can be found by digging deeper into Design Patterns. ... >(just one of thousands of links about design patterns, ... >definitions in order to create the concept of a contract where any object ... (this ability to substitute forms the ...
    (microsoft.public.dotnet.languages.csharp)