View Single Post
  #1 (permalink)  
Old September 6th, 2006, 12:26 AM
aldwinenriquez aldwinenriquez is offline
Authorized User
 
Join Date: Jun 2005
Location: , , Philippines.
Posts: 97
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to aldwinenriquez
Default Object Design Pattern problem

We have an object called Product and ProductCollection defined below:
class Product{
public string Name;
public Type.Category Category;
}

class ProductCollection{
public Product[] List;
}


what we want to do is to add an attribute to the Product class by creating a derived class called ProductChild(inherits from Product) which will contain the additional attributes.


class ProductChild : Product{
public string AdditionalAttribute;
}

class ProductChildCollection{
public new ProductChild[] List;
}

The problem is how to to Create a ProductChildCollection class and cast(convert) the parent ProductCollection into ProductChildCollection without iterating throught the Product List in the ProductCollection.

ProductChildCollection childCollection = (ProductChildCollection)ProductCollection();//casting problem, cannot cast a parent into a child

Our initial solution is to iterate through the ProductCollection and generate child objects from that.


Once that is done we can then set the properties of the additional attributes into each of the ProductChild List items from ProductChildCollection class.

Any ideas?



"Dont you ever give up!"
__________________
\"Dont you ever give up!\"
Reply With Quote