I'd like to code a function like the following
public void Foo(System.Type t where t : MyClass)
{ ... }
In other words, the argument type is System.Type, and I want to restrict the allowed Types to those that derive from MyClass.
Is there any way to specify this syntactically, or does t have to be checked at runtime?
...
I'm trying to create a set of classes where a common ancestor is responsible for all the logic involved in setting various properties, and the descendants just change the access of properties depending on whether they are required in the particular descendant.
When I try to do it as shown below I get a compiler error: "cannot change acc...
I ran into a problem where after my class overrode a function of its base class, all of the overloaded versions of the functions were then hidden. Is this by design or am I just doing something wrong?
Ex.
class foo
{
public:
foo(void);
~foo(void);
virtual void a(int);
virtual void a(double);
};
class bar : public fo...
class Base {
public:
void foo() const {
std::cout << "foo const" << std::endl;
}
};
class Derived : public Base {
public:
void foo() {
std::cout << "foo"<< std::endl;
}
}
I want to make sure that foo() const is correctly hidden for Base. Yeah, this is a bad i...
Hi, does anyone know why this gives a compiler error ? I tried VS 2005 and Codewarrior:
class Parent {
protected:
int m_Var;
public:
Parent() : m_Var(0) {}
virtual ~Parent() {}
void PubFunc();
};
class Child : public Parent {
protected:
bool m_Bool;
public:
Child() : m_Bool(false) {}
...
I'm currently writing some intranet web application where people could submit to admins requests for adding different resources. The example requests would be:
installing programs, in this case user will select which program he wants installed
increasing quota, in this case user will just enter the amount of disk space he needs or may...
I am trying to use reflection to determine which methods a derived class overrides from a base class. It is fairly easy to determine if the method is not overridden, but trying to determine if a method is overridden in a base class, or simply created as virtual in the derived class is what I am trying to accomplish.
So, if Class A has ...
Hi all,
first question here, so hopefully you'll all go gently on me!
I've been reading an awful lot over the past few days about polymorphism, and trying to apply it to what I do in c#, and it seems there are a few different ways to implement it. I hope I've gotten a handle on this, but I'd be delighted even if I haven't for clarific...
I'm still a novice when it comes to polymorphism so I hope I can phrase my question correctly.
Let's say I have tables in my Database - Dog, Cat and Mouse. I want to be able to call something like:
$animal = new Animal("dog", 12);
with the animal class being something like:
class Animal {
protected $id;
protected $legs;
prote...
I have 2 objects to create that are identical except for that they refer to my dev and test WCF services. Basically, these are the object for the service itself, and the object for a DTO created by the WCF data-contract.
In my test client, I create either the 2 objects related to the dev WCF service, or the 2 objects related to the tes...
I am designing a dashboard to display corporate metrics (currently with ASP.net 3.5 in C#), and looking for advice on design. I'm not as used to OOP in web applications.
There may be many different metrics that can be seen by different users in a Many-to-Many relationship. I am storing the users in a local SQL database and it of cours...
Good day.
This is a Hibnerate polymorphism question and a data model design
question; they are intertwingled. I've used Hibernate in the past,
and have enjoyed it, but sometimes I find it difficult to think
about anything but trivial designs. Not a knock on Hibernate; just
an observation that ORM in general can be challenging.
I thin...
Working on a simple example of double sided polymorphic relationships using the has_ many_ polymorphs ActiveRecord plugin. I have two classes, "cats" and "dogs", which can have "friendships" with each other, so three classes in all: "cats", "dogs" and "friendships". A cat can be friends with a dog (yes, it does happen!) and of course als...
In Java i have abstract class named Operation and three its subclasses called OperationActivation, OperationPayment and OperationSendEmail.
ADDED FROM COMMENT: Operation* objects are EJB Entity Beans so I can't have business logic inside them.
No I want to create processor class like this:
public class ProcessOperationService {
publi...
Suppose I have the following:
class Shape a where
draw a :: a -> IO ()
data Rectangle = Rectangle Int Int
instance Shape Rectangle where
draw (Rectangle length width) = ...
data Circle = Circle Int Int
instance Shape Circle where
draw (Circle center radius) = ...
Is there any way for me to define a list of shapes, trav...
I have a hierarchy of types - GenericClass and a number of derived classes, InterestingDerivedClass included, GenericClass is polymorphic. There's an interface
interface ICallback {
virtual void DoStuff( GenericClass* ) = 0;
};
which I need to implement. Then I want to detect the case when GenericClass* pointer passed into ICallba...
I am using a base class and there are 5 child classes currently for it. Some of the functions are similar for 3 of the children but not all of them. I cannot introduce a new level of hierarchy as some methods are repeated in child 1,2,3 and some in 2,3,4.
How best can I avoid overriding the methods in all 3 children and repeating the co...
I have three different base classes:
class BaseA
{
public:
virtual int foo() = 0;
};
class BaseB
{
public:
virtual int foo() { return 42; }
};
class BaseC
{
public:
int foo() { return 42; }
};
I then derive from the base like this (substitute X for A, B or C):
class Child : public BaseX
{
public:
int foo() { return ...
I was watching a googletechtalks video and they frequently refered to polymorphism what is it, what is it for, and how it it used?
...
Suppose I have 3 models, Car, Motorcycle and Truck, and for each I have to enter a bunch of stuff, such as a list of known previous owners, traffic tickets, license plates, etc. So I created a model for each (PreviousOwners, PreviousPlates, etc) and set up polymorphic associations for the related models.
The problem is, how can I enter ...