471,071 Members | 1,325 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,071 software developers and data experts.

need some realworld examples

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.

thanks,
mj
Nov 21 '05 #1
2 1102
Don

"mattie" <ma****@discussions.microsoft.com> wrote in message
news:F6**********************************@microsof t.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
Nov 21 '05 #2
thank you.

"Don" wrote:

"mattie" <ma****@discussions.microsoft.com> wrote in message
news:F6**********************************@microsof t.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

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Marc | last post: by
22 posts views Thread by Rafia Tapia | last post: by
11 posts views Thread by Larry | last post: by
1 post views Thread by skootr | last post: by
2 posts views Thread by jasiu85 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.