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 " 6 3267
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 "
Tamir,
Basically, you would want a class factory. You would pass the factory
the type, and it would return the interface or abstract base class.
When constructing the class, you would use reflection. You would get
the constructor from the Type for the implementation, and then call it,
passing the parameter. Since you can't define the contract through an
interface, you have to encapsulate the contract through a class factory.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:Ob**************@tk2msftngp13.phx.gbl... 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 "
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" <ph********@discussions.microsoft.com> wrote in message
news:47**********************************@microsof t.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 "
It seemed I can not use reflection here, due all of those objects are in the
same class with caller
--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:eE**************@TK2MSFTNGP10.phx.gbl... Tamir,
Basically, you would want a class factory. You would pass the factory the type, and it would return the interface or abstract base class.
When constructing the class, you would use reflection. You would get the constructor from the Type for the implementation, and then call it, passing the parameter. Since you can't define the contract through an interface, you have to encapsulate the contract through a class factory.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message news:Ob**************@tk2msftngp13.phx.gbl...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 "
Tamir,
What do you mean all of the objects are in the same class with the
caller? That shouldn't mean that you can't use reflection, you just aren't
using it properly. Can you show what you mean? It would help point out how
to use reflection here.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:%2******************@tk2msftngp13.phx.gbl... It seemed I can not use reflection here, due all of those objects are in the same class with caller
-- Tamir Khason You want dot.NET? Just ask: "Please, www.dotnet.us "
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:eE**************@TK2MSFTNGP10.phx.gbl... Tamir,
Basically, you would want a class factory. You would pass the factory the type, and it would return the interface or abstract base class.
When constructing the class, you would use reflection. You would get the constructor from the Type for the implementation, and then call it, passing the parameter. Since you can't define the contract through an interface, you have to encapsulate the contract through a class factory.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message news:Ob**************@tk2msftngp13.phx.gbl...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 "
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" <ph********@discussions.microsoft.com> wrote in message news:47**********************************@microsof t.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 " This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Anon Email |
last post by:
Hi people,
I'm learning about header files in C++. The following is code from
Bartosz Milewski:
// Code
const int maxStack = 16;
class IStack
|
by: Chris Capel |
last post by:
What is the rationale behind the decision not to allow abstract static class
members? It doesn't seem like it's a logically contradictory concept, or
that the implementation would be difficult or...
|
by: Mike Ruane-Torr |
last post by:
Why can't I have a static abstract method in C#?
My intention is to have a class-level method that returns a string to
supply information about inherited classes, and it is natural to make this...
|
by: Ole Hanson |
last post by:
I am accessing my database through an interface, to allow future
substitution of the physical datastore - hence I would like to declare in my
Interface that my DAL-objects implementing the...
|
by: Picho |
last post by:
Hi all,
I popped up this question a while ago, and I thought it was worth checking
again now... (maybe something has changed or something will change).
I read this book about component...
|
by: Lamefif |
last post by:
// C3DRect supports IDraw and IShapeEdit.
class C3DRect : public IDraw, public IShapeEdit
{
public:
C3DRect();
virtual ~C3DRect();
// IDraw
virtual void Draw();
// IShapeEdit
virtual void...
|
by: cmonthenet |
last post by:
Hello,
I searched for an answer to my question and found similar posts,
but none that quite addressed the issue I am trying to resolve.
Essentially, it seems like I need something like a virtual...
|
by: =?Utf-8?B?Y2FybG0=?= |
last post by:
Hello,
I searched for an answer to my question and found similar posts,
but none that quite addressed the issue I am trying to resolve.
Essentially, it seems like I need something like a virtual...
|
by: Markus Dehmann |
last post by:
I need a simple object serialization, where loading an object from
file looks like this:
Foo* foo1 = FooFactory::create("./saved/foo1.a321f23d");
Foo* foo2 =...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |