Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

what is the advantage of using interface?

Status
Not open for further replies.

beeleegie

Programmer
May 15, 2002
42
0
0
HK
What's the advantage of interface class in our system design?
I only can figure out these advantages:
1. defines a protocol for different classes to implement
2. hides the implemented class from interface user
3. Ensure a given class have a specific function on it

So how it can increase our development process and extensibility of our system?
 
Class a, b, and c use interface z.

Now, in your code, you only need to write one sub that takes a parameter of z

i.e.
Public Sub Process(Value as z)

Otherwise, you'd have to overload the sub to take any of the classes
i.e.

Public Overloaded Sub Process(Value as a)
Public Overloaded Sub Process(Value as b)
Public Overloaded Sub Process(Value as c)

So in the long run, using interfaces can decrease the overall amount of code you have to write.

Thats one benefit, i'm sure others with more experience using them have more to offer.
:)

D'Arcy


 
Here are a couple more uses.
Suppose you're testing some new code that uses another class. Suppose further that the other class...
(a) doesn't exists yet, or
(b) isn't complete yet, or
(c) is slow to use and makes your testing too slow
(e) may respond in a variable way due to external cicumstances (when you want a predictable response so you can test)
Then you can declare an interface that the other class should implement, which defines a sort of 'contract' that this class has to meet, then write a 'mock' class that also implements the interface and have it behave in the way you need to test your own code.

Secondly, use interfaces to ensure that all classes that use a common service class can be passed to that service as the interface class. For example, in order to use my PivotEngine class (which turns vectors into 2-D tables), any class that may be pivoted has to implement the IPivot interface.

Mike
 
To add my two pence...

In system design, the concept of <<interface>> doesnt necessarily mean Ixxxx, be it in C++/COM, VB, Delphi or whatever. It is a conceptual term to refer to something abstract. Earlier in design something could be demarked as <<interface>>, but later turn into a class during design.

For me thats important, as well as the concept of type.

Nick.

 
Hello all.

The true power of interfaces arise when software evolve. If you have designed an interface between two systems and one of them change, for example migrating from one tecnology to another (domino to J2EE, CICS to Tuxedo, etc) or adding new functionality, or deleting obsolete functionality, etc the second system will need no changes.

Interfaces, as conceptual term and more important, as a design-by-contract technique, are really useful in large-scale-quickly-evolving projects. Consider a bus macro-architecture:

System 1 System 2 ... System N
| | |
<======================================================>
| | |
System N+1 System N+2 ... System M

If you have a well-defined bus-interface, changes in any system will carry less cost than if you don't have implemented interfaces.

Moreover, In a *VERY* big and *VERY* complex system, you can see even double bus architectures; for example:

System 1 System 2 ... System N Old
| | | Tibco
<================================================> Based
| | | | Bus
System N+1 | System N+2 ... System M
|
|
Bus Bridge
|
|
System M+1 | System M+2 ... System P New
| | | | XML
<================================================> Based
| | | Bus
System P+1 System P+2 ... System Q

Can you imagine what chaos would be if no interfaces were defined?

I hope now you understand how important interfaces (and adaptors, bridges, proxies, etc) are.

Best Regards.

Nacho Vargas.
Consultant.
D.M.R. Consulting (a Fujitsu Company)
 
And that's just what makes the analysis and design of interfaces such an important subject and it should be handled properly.
An interface design should focus not only on current aspects of the problem but take into consideration the evolving of the software. A robust interface design should allow a software to be modified over a period of time and not restrict its capabilities.

Of course, this would be the programmers' wonderland, but there are enough areas where you can design a good interface. [red]Nosferatu[/red]
We are what we eat...
There's no such thing as free meal...
once stated: methane@personal.ro
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top