By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,894 Members | 1,937 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,894 IT Pros & Developers. It's quick & easy.

Fairly simple inheritance and polymorphism

P: n/a
Hi

I was wondering if you could help me - I am looking at creating a C#
Project to be used with my ASP.NET solition (VS2005). What I would
like to do (I believe) is really simple.

I have an 'Order' object, and each 'Order' can have one (and only one)
'OrderLine'. The order line is the item ordered if you like. What I
would like to do is be able to access my 'OrderLine' via an instance of
the 'Order' object.

// i.e.
Order oOrder = new Order(iOrderID);
String sSomething = oOrder.OrderLine.ProductName;

// and also things like
oOrder.OrderLine.Delete();
oOrder.OrderLine.ProductName = "Widget";
>From within my 'OrderLine' I would like to be able to access methods
etc. from my Order object. Can anybody tell me where to begin?

Many thanks

Darren

Sep 25 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Indeed, very simple:

public class OrderLine
{
private Order order;
private OrderLine()
{
// don't allow parameterless instancing
}
public OrderLine(Order order)
: base()
{
if (order == null)
throw new ArgumentNullException("order may not be null!");
this.order = order;
}
private string productName;
public string ProductName
{
get { return productName; }
set { productName= value; }
}
// add more properties here
// ...

public void Delete()
{
if (order != null)
order.orderLine = null;
}
}
public class Order
{
internal OrderLine orderLine = null;
public OrderLine OrderLine
{
get
{
// if orderLine is null, you either deleted it or it hasn't
been added yet
// in either case, create a new instance if needed
if (orderLine == null)
orderLine = new OrderLine(this);
return orderLine;
}

}
}

--
Regards, Peter

"daz_oldham" <Da**************@gmail.comskrev i meddelandet
news:11**********************@b28g2000cwb.googlegr oups.com...
Hi

I was wondering if you could help me - I am looking at creating a C#
Project to be used with my ASP.NET solition (VS2005). What I would
like to do (I believe) is really simple.

I have an 'Order' object, and each 'Order' can have one (and only one)
'OrderLine'. The order line is the item ordered if you like. What I
would like to do is be able to access my 'OrderLine' via an instance of
the 'Order' object.

// i.e.
Order oOrder = new Order(iOrderID);
String sSomething = oOrder.OrderLine.ProductName;

// and also things like
oOrder.OrderLine.Delete();
oOrder.OrderLine.ProductName = "Widget";
>>From within my 'OrderLine' I would like to be able to access methods
etc. from my Order object. Can anybody tell me where to begin?

Many thanks

Darren

Sep 25 '06 #2

P: n/a
Hi Peter

Though it is very late - thankyou for your reply.

I have been unable to access Google Groups for some reason, but I am
back on now :)

Thanks again

Darren

Peter Thornqvist wrote:
Indeed, very simple:

public class OrderLine
{
private Order order;
private OrderLine()
{
// don't allow parameterless instancing
}
public OrderLine(Order order)
: base()
{
if (order == null)
throw new ArgumentNullException("order may not be null!");
this.order = order;
}
private string productName;
public string ProductName
{
get { return productName; }
set { productName= value; }
}
// add more properties here
// ...

public void Delete()
{
if (order != null)
order.orderLine = null;
}
}
public class Order
{
internal OrderLine orderLine = null;
public OrderLine OrderLine
{
get
{
// if orderLine is null, you either deleted it or it hasn't
been added yet
// in either case, create a new instance if needed
if (orderLine == null)
orderLine = new OrderLine(this);
return orderLine;
}

}
}

--
Regards, Peter

"daz_oldham" <Da**************@gmail.comskrev i meddelandet
news:11**********************@b28g2000cwb.googlegr oups.com...
Hi

I was wondering if you could help me - I am looking at creating a C#
Project to be used with my ASP.NET solition (VS2005). What I would
like to do (I believe) is really simple.

I have an 'Order' object, and each 'Order' can have one (and only one)
'OrderLine'. The order line is the item ordered if you like. What I
would like to do is be able to access my 'OrderLine' via an instance of
the 'Order' object.

// i.e.
Order oOrder = new Order(iOrderID);
String sSomething = oOrder.OrderLine.ProductName;

// and also things like
oOrder.OrderLine.Delete();
oOrder.OrderLine.ProductName = "Widget";
>From within my 'OrderLine' I would like to be able to access methods
etc. from my Order object. Can anybody tell me where to begin?

Many thanks

Darren
Oct 17 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.