Re: Interfaces vs Classes
From: Frank Rizzo (none_at_none.com)
Date: 02/24/05
- Next message: Craig: "Re: Create a COM Object with C#?"
- Previous message: Paul Aspinall: "Re: Call a javascript function from C#"
- In reply to: Telmo Sampaio: "Re: Interfaces vs Classes"
- Next in thread: Michael S: "Re: Interfaces vs Classes"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 24 Feb 2005 14:05:50 -0800
Thanks, this was helpful. However, my design doesn't fall into this
category.
Telmo Sampaio wrote:
> I wrote this last night... I dunno why it did not go thru...
>
> Hi Frank,
>
> It is normal to feel like that. The big advantage of using interfaces is
> that they extend the use of polymorphism beyond the class hierarchy. They
> are normally used to create small frameworks as well. Here are two examples:
>
> - imagine you are responsible for writing an ATM application for a bank.
> Thru your application you will allow users to Deposit, Withdraw and check
> their Balance for Checking accounts and Savings Accounts. No matter what
> kind of account your application handles, it needs to execute those tree
> operations. You can sure derive Checking and Savings from an abstract
> BankAccount that contain the necessary members. Now imagine that in the
> future, your ATM application may also be used to access Credit Card accounts
> and that the CreditCard class is not in the same inheritance hierarchy as
> the BankAccounts. You still need to force it to have the Deposit, Withdraw
> and Balance members. An interface is the perfect solution here.
>
> - another real example. You are probably aware of the Sort method for the
> Array class. It sorts data in a single dimension array. Remember that arrays
> can be of any type: integers, strings, Animals, BankAccounts, etc. The Sort
> method does not care about the data type. It access the underlying object
> thru the IComparable interface. Therefore, to make your classes sortable,
> you need to implement the IComparable interface. This has nothing to do with
> inheritance.
>
> I hope this helps a little bit.
>
> Telmo Sampaio
> MCT
>
> "Frank Rizzo" <none@none.com> wrote in message
> news:eybBWJhGFHA.2748@tk2msftngp13.phx.gbl...
>
>>We are having one of those religious debates at work: Interfaces vs
>>Classes. My take is that Classes give you more flexibility. You can
>>enforce a contract on the descendant classes by marking methods abstract
>>(which is all that an interface does). In addition, the classes allow you
>>to be flexible by adding functionality that child classes inherit. Or by
>>providing optional functionality via virtual methods.
>>
>>Now, I understand that Interfaces have its place, but I am having a hard
>>time finding a situation where the classes (via inheritance) do not
>>provide an identical or better solution.
>>
>>Am I missing something? I am open to arguments from both sides.
>>
>>Regards.
>
>
>
- Next message: Craig: "Re: Create a COM Object with C#?"
- Previous message: Paul Aspinall: "Re: Call a javascript function from C#"
- In reply to: Telmo Sampaio: "Re: Interfaces vs Classes"
- Next in thread: Michael S: "Re: Interfaces vs Classes"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|