Re: Static Interface/Abstract/Virtual
From: phreakstar (phreakstar_at_discussions.microsoft.com)
Date: 11/24/04
- Next message: Wm. Scott Miller: "Re: Securing hashing algorithm"
- Previous message: R.A.: "how to return xml document from a web service"
- In reply to: Tamir Khason: "Re: Static Interface/Abstract/Virtual"
- Next in thread: Nicholas Paldino [.NET/C# MVP]: "Re: Static Interface/Abstract/Virtual"
- Messages sorted by: [ date ] [ thread ]
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 "
> >>
> >>
> >>
>
>
>
- Next message: Wm. Scott Miller: "Re: Securing hashing algorithm"
- Previous message: R.A.: "how to return xml document from a web service"
- In reply to: Tamir Khason: "Re: Static Interface/Abstract/Virtual"
- Next in thread: Nicholas Paldino [.NET/C# MVP]: "Re: Static Interface/Abstract/Virtual"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|