Re: need some realworld examples
From: mattie (mattie_at_discussions.microsoft.com)
Date: 01/31/05
- Next message: VBen: "Re: Is there an event for image change for a PictureBox Control? please help."
- Previous message: cr113_at_hotmail.com: "How to programmically use a dialup connection."
- In reply to: Don: "Re: need some realworld examples"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 31 Jan 2005 13:19:05 -0800
thank you.
"Don" wrote:
>
> "mattie" <mattie@discussions.microsoft.com> wrote in message
> news:F654E1FD-F88F-4C69-8A2B-98E704105F05@microsoft.com...
> > hi,
> >
> > i was just reading an article on interface-based programming and the
> example
> > they used was pretty good to get the concept across.
> >
> > dim dog as IDog
> > dog=new CBeagle
> > dog.bark
> >
> > ok, i kinda understand. but i can't imagine what to relate this to in the
> > business world. could you give some quick examples and explanations of
> > business related topics where this would be useful. please, the more
> examples
> > and analogies the better. very new to this.
>
>
> For one, instantiating objects using interfaces allows you to be more
> specific later on your code. e.g.:
>
> Dim dog as IDog
>
> If userWantsANiceDog then
> dog = new GermanShepherd
> Else
> dog = new Chihuahua
> End If
>
> dog.bark
>
>
> One example with which you might use interfaces in variable declarations
> might be if you had some of contact management program in which a contact
> might be a person or a business. You might do something like this:
>
> (pseudocode)
>
> IContact interface
> Function PrintDetails()
>
> PatientContact class
> Property FirstName
> Property LastName
> Implements PrintDetails()
> Print FirstName & " " & LastName
>
> BusinessContact class
> Property CompanyName
> Implements PrintDetails()
> Print CompanyName
>
>
> Here you have an interface (IContact) with one method: PrintDetails. You
> also have two classes (PatientContact and BusinessContact), both of which
> implement IContact. As you can see, each one implements the PrintDetails
> method differently, though, because they store different information. When
> you have something like the above, you can do neat things like this:
>
> Public Function PrintContactDetails(ByVal contact as IContact)
>
> contact.PrintDetails
>
> End Function
>
> This function will take either PatientContact or BusinessContact objects and
> tell them to print their details.
>
> Imagine an inventory control system. You might have an interface called
> IProduct. Every product class could implement this class, and it could
> provide methods for doing general tasks like retrieving a product
> description or whatever. Then your business logic would just work with
> IProduct objects whenever it doesn't care about what specific kind of
> product it might be (for example, you might just be displaying a list of
> product names).
>
> I recently stumbled onto this stuff. It comes in really handy sometimes.
>
> - Don
>
>
>
- Next message: VBen: "Re: Is there an event for image change for a PictureBox Control? please help."
- Previous message: cr113_at_hotmail.com: "How to programmically use a dialup connection."
- In reply to: Don: "Re: need some realworld examples"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|