passing parameter as an interface type

W

wiredless

What is the advantage of passing an interface type?

according to UML (visio) when i reverse engineer existing code to a UML
diagram I get the error

"UMLE00046: sample[Parameter] : [Parameter - WFR1] - An interface cannot be
used as the type of a parameter."

for this code:

public void OnUpdate(CCC.Sys.TestProc.ISample sample)
{

however the application does compile and run correctly.

Yes its not my code.

What is the advantage of passing an interface type?
Since UML doesn't like it should I not do it?

Thanks
 
T

Tom Porterfield

wiredless said:
What is the advantage of passing an interface type?

according to UML (visio) when i reverse engineer existing code to a UML
diagram I get the error

"UMLE00046: sample[Parameter] : [Parameter - WFR1] - An interface cannot be
used as the type of a parameter."

for this code:

public void OnUpdate(CCC.Sys.TestProc.ISample sample)
{

however the application does compile and run correctly.

Yes its not my code.

What is the advantage of passing an interface type?
Since UML doesn't like it should I not do it?

The advantage is that it makes your code less susceptible to requiring
modification for future enhancements. By taking an interface type
rather than a specific object, all you worry about is that whatever is
passed support the functionality that the OnUpdate method needs. How
the ISample object implements the interface does not matter to you.

I'm not enough of a Visio and/or UML guru to say why the error is being
generated.
 
R

Richard Blewett [DevelopMentor]

Passing an interface as a method parameter is a totally valid thing to do. Consider this:

interface IPolygon

{

void Draw();

}

class Visio

{

public void DrawDiagram(IPolygon[] shapes)

{

foreach( IPolygon p in shapes )

{

p.Draw();

}

}

}

So you would think Visio should know better ;-)

Regards

Richard Blewett - DevelopMentor

http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<#[email protected]>

What is the advantage of passing an interface type?

according to UML (visio) when i reverse engineer existing code to a UML
diagram I get the error

"UMLE00046: sample[Parameter] : [Parameter - WFR1] - An interface cannot be
used as the type of a parameter."

for this code:

public void OnUpdate(CCC.Sys.TestProc.ISample sample)
{

however the application does compile and run correctly.

Yes its not my code.

What is the advantage of passing an interface type?
Since UML doesn't like it should I not do it?

Thanks



---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.766 / Virus Database: 513 - Release Date: 17/09/2004



[microsoft.public.dotnet.languages.csharp]
 
J

Jay B. Harlow [MVP - Outlook]

wiredless,
The others have discussed the advantages of using an Interface.

The version of UML that Visio adheres to does not allow interfaces to be
parameters, hence the error.

However you can turn the check off using "UML - Options - UML Document -
Relax semantic error checking".

Hope this helps
Jay
 
D

DurayAkar

Can you bypass just a certain semantic error like this one ?

I want to use the other semantic errors checked, but not this...

Because the System classes has this structure themselves :)
 
D

DurayAkar

Is it possible to exclude just this error instead of relaxing the whole
deal?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top