E
EvelynWilde
Just when I thought I'd got my head around inheritance, I'm confused -
here's a quasi-scenario:
I have an object representing a Department in my shop. It's the
sausages department, and has properties (DepartmentName, FloorArea,
Manager etc). I also have an object representing a Product (SKU, Price
etc.).
I've set up my Product to inherit from my Department. This seems
logical: all Products 'belong' in a Deparment. I've written a
GetProduct method on the Department, which returns a new Product.
While I can happily access my Department methods through my Product,
they don't return anything. e.g. Product.DepartmentName is empty - it
can be set, but will be 'disconnected' from the Department, it seems.
So I'm concluding that inheritance inherits the methods and
properties, but not the context.
So I suppose the question is: what's the best way to do this sort of
thing? How should my Product best inherit a specific instance of my
Department (and thus all its associated properties), rather than the
generic object? Is there an elegant way of doing it, or do I have to
shuffle lots of values about?
Thanks, A
here's a quasi-scenario:
I have an object representing a Department in my shop. It's the
sausages department, and has properties (DepartmentName, FloorArea,
Manager etc). I also have an object representing a Product (SKU, Price
etc.).
I've set up my Product to inherit from my Department. This seems
logical: all Products 'belong' in a Deparment. I've written a
GetProduct method on the Department, which returns a new Product.
While I can happily access my Department methods through my Product,
they don't return anything. e.g. Product.DepartmentName is empty - it
can be set, but will be 'disconnected' from the Department, it seems.
So I'm concluding that inheritance inherits the methods and
properties, but not the context.
So I suppose the question is: what's the best way to do this sort of
thing? How should my Product best inherit a specific instance of my
Department (and thus all its associated properties), rather than the
generic object? Is there an elegant way of doing it, or do I have to
shuffle lots of values about?
Thanks, A