Y
yohaas
I'm trying to do something, not sure if it's possible or even if it
makes sense, but I figured I'd throw it out there.
I have a class OrderSummary that contains information about an order. I
then have two classes that inherit OrderSummary; K_OrderSummary and
M_OrderSummary which are specific types of orders. I will not know what
type of order it is until runtime so I want to create an object of type
OrderSummary. I only want to have to choose the type once for each
order (at runtime).
for example:
OrderSummary o;
//this will be done once, when the object is created, then the rest of
the code can just use type OrderSummary
if(type.Equals("k"){
o = new K_OrderSummary();
}
else{
o = new M_OrderSummary();
}
private void DoSomethingToOrder(OrderSummary order){
order.Something(); //this would call M_OrderSummary.Something() or
K_OrderSummary.Something() depending on what type of order it is.
}
Essentially, I want to use inheritance, but be able to declare the
object as the parent type, but use the child functions.
It would be similar to doing this:
Object o = new Form();
and then expect to be able to use o as if it were a Form object. The
declaration works, because Form inherits Object, but I of course do not
have access the the Form functions.
Make any sense?
Thanks,
Yohaas
makes sense, but I figured I'd throw it out there.
I have a class OrderSummary that contains information about an order. I
then have two classes that inherit OrderSummary; K_OrderSummary and
M_OrderSummary which are specific types of orders. I will not know what
type of order it is until runtime so I want to create an object of type
OrderSummary. I only want to have to choose the type once for each
order (at runtime).
for example:
OrderSummary o;
//this will be done once, when the object is created, then the rest of
the code can just use type OrderSummary
if(type.Equals("k"){
o = new K_OrderSummary();
}
else{
o = new M_OrderSummary();
}
private void DoSomethingToOrder(OrderSummary order){
order.Something(); //this would call M_OrderSummary.Something() or
K_OrderSummary.Something() depending on what type of order it is.
}
Essentially, I want to use inheritance, but be able to declare the
object as the parent type, but use the child functions.
It would be similar to doing this:
Object o = new Form();
and then expect to be able to use o as if it were a Form object. The
declaration works, because Form inherits Object, but I of course do not
have access the the Form functions.
Make any sense?
Thanks,
Yohaas