Contract to require a certain shared method

  • Thread starter Thread starter Bryan
  • Start date Start date
B

Bryan

I was trying to write an interface that would require the implementing
class to have a shared function, CanAdd() as boolean, which decides if
the current user can add a new instance of the particular class. This
authorization is at the class level, not the instance level, so it
should be shared, but I cannot find a way to require a class to
implement a shared method via an interface. Any suggestions?
 
Bryan,

Luckely you can AFAIK in VB not create mixed mode classes (some which need a
constructor and some which don't allow a constructer).

Legency this is in the C languages.

Cor
 
Cor Ligthert said:
Luckely you can AFAIK in VB not create mixed mode classes (some which need
a constructor and some which don't allow a constructer).

What's the relation to the OP's question?
Legency this is in the C languages.

At least not in C because C doesn't support classes at all.
 
Bryan said:
I was trying to write an interface that would require the implementing
class to have a shared function, CanAdd() as boolean, which decides if
the current user can add a new instance of the particular class. This
authorization is at the class level, not the instance level, so it
should be shared, but I cannot find a way to require a class to
implement a shared method via an interface. Any suggestions?

That's simply not possible in VB (and in C# too). However, why not define a
base class containing the method? However, note that it's not possible to
override shared methods at all.
 
That's simply not possible in VB (and in C# too). However, why not define a
base class containing the method? However, note that it's not possible to
override shared methods at all.

I can't make the member part of a base class because it needs to
behave differently for each class. The method needs to be shared, and
I would just like to avoid any sort of late binding method calling.
 
Bryan said:
I can't make the member part of a base class because it needs to
behave differently for each class. The method needs to be shared, and
I would just like to avoid any sort of late binding method calling.

Maybe you can utilize the Factory design pattern.
 
Back
Top