Re: Static Interface/Abstract/Virtual

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: phreakstar (phreakstar_at_discussions.microsoft.com)
Date: 11/24/04


Date: Wed, 24 Nov 2004 07:15:06 -0800

Well then you need to try each type. It isn't that Interfaces or Abstract
types don't take constructors with parameters, they don't have constructors
at all, they are Abstract. It wouldn't make any sense to implement an
interface or abstract type anyways. Since they have no implementation what
would you do with it? Just calling an Interface with a constructor and
passing a value won't call every class that implements that Interface, that
just isn't the way it works. You're going to need to go through each type and
try to call them. Or make a procedure that calls them with your variable and
then pass each type individually into it.

In my opinion you need to re-evaluate your design. If you have several
objects that all accept the same value, and only one will work with that then
perhaps the value itself needs to be an object and call each type that it can
work on to see which one it works with. Or if you want to just call one
function that calls many functions then maybe you can look into using a
delegate. But at some point, each of these types is going to have to be
individually instantiated using its concrete class, since there really is no
other way to do it.

Maybe create all the types into an array whose type is your interface type
and then iterate through the array (or collection) and perform the same
operation on each item in the array/collection. It is hard to give
suggestions without knowing more about your architecture.

Thanks,
Justin Etheredge
"Tamir Khason" wrote:

> Basicly, only one object will not return exception in my certain case... It
> parameter based. If the object can not work with parameter transferred it'll
> thow exception.
>
> --
> Tamir Khason
> You want dot.NET? Just ask:
> "Please, www.dotnet.us "
>
> "phreakstar" <phreakstar@discussions.microsoft.com> wrote in message
> news:471979F2-935B-44A0-86E2-4642ED20BF3F@microsoft.com...
> > Well, how do you determine which object you need when you create them?
> > Usually what some people will do is create a "Class factory" which when
> > passed certain parameters determines which class you actually need and
> > returns it to your Interface type or base type.
> >
> > Thanks,
> > Justin Etheredge
> >
> > "Tamir Khason" wrote:
> >
> >> I have some classes that basicly do the same things but different way.
> >> There are no default constructors in those classes each constructor
> >> should
> >> recieve same value
> >>
> >> So
> >>
> >> Fooclass:MyBasicClass or Fooclass:IBasicClass
> >>
> >> and I want to be able to call form program something like this:
> >>
> >> MyBasicClass foo = new MyBasicClass(value);
> >> or
> >> IBasicInterface foo = new IBasicInterface(value);
> >>
> >> Interfaces,Abstracts or Virtuals does not support constructors with
> >> parameters
> >>
> >> So trying:
> >>
> >> MyBasicClass foo = MyBasicClass.GetInstance(value);
> >> or
> >> IBasicInterface foo = IBasicInterface.GetInstance(value);
> >>
> >> and in each class something like
> >> if(this=null)
> >> return new Fooclass(value);
> >> else
> >> return this;
> >>
> >> But I can not create static methods neither in interface, abstract or
> >> virtual
> >>
> >> So how to implement such architecture???
> >>
> >> TNX
> >>
> >> --
> >> Tamir Khason
> >> You want dot.NET? Just ask:
> >> "Please, www.dotnet.us "
> >>
> >>
> >>
>
>
>



Relevant Pages

  • Re: writing drivers using C++
    ... declaration will lead to a subroutine invocation. ... Whether a class has overloaded operators is part of ... the interface of that class, ... Without using classes whose constructors allocate ressources in need ...
    (comp.os.linux.development.system)
  • Re: virtual inheritance nightmare
    ... But it _might_ be used if you derive from Interface and make that class ... > virtual void DoThing() ... The work-around here is to declare 'Interface*' constructors ...
    (comp.lang.cpp)
  • Re: writing drivers using C++
    ... Whether a class has overloaded operators is part of ... the interface of that class, ... 'cleanup code' can often be avoided (eg by allocating ... temporary buffers of any kind on the stack, which constructors cannot ...
    (comp.os.linux.development.system)
  • Re: 7.0 wishlist?
    ... Any object can be used where an interface type is expected if it has the right set of method signatures, whether or not it "implements" the interface using that keyword. ... More typing than a single punctuation mark, by a factor of eight -- nearly an order of magnitude. ... Works, but if the array doesn't need to be modifiable, creates a wasteful duplicate every time. ... all the collections really ought to have constructors that take an Iterable and just iterate over it. ...
    (comp.lang.java.programmer)
  • Newbie
    ... As a migrant from COBOL to Java, i was amazed to see a mainmethod of a ... C++ had a concept of copy constructors to handle pass by values (though i ... implementation without the need to define the interface methods.Are there ... such interface types and if so, ...
    (microsoft.public.dotnet.languages.csharp)