tags:

views:

113

answers:

3

I have a class that is being used by two different processes with each process using different properties of the class. Everytime a process requires a new property I simply add it to the class. Is this a bad idea? Should I just create two separate classes and update them when required?

N.B. At times the same property is being used by both the processes and each process uses a different instance of the class.

+6  A: 

Common properties can be kept in a single class. Then you can derive two different classes from the common class and add specific properties.

Kirtan
Moreover, the deriving classes need not be in the same library/namespace as the derived classes. Have each project/program that inherits the base class create it's own child class in it's own namespace so that an update to one project doesn't affect the other project. Only when the base class (shared) properties change will you need to recompile both projects.
tvanfosson
A: 

Use a member list containing (named property, value) pairs in the class. Couple this with a factory with 2 methods returning instances seeded with the right set of properties.

Gishu
+1  A: 

"Common properties can be kept in a single class. Then you can derive two different classes from the common class and add specific properties" - Kirtan Gor

class BaseClassWithSharedProperties
{
    public Int32 SharedId { get; set; }
    public String SharedName { get; get; }
}

class UniqueClassNumberOne : BaseClassWithSharedProperties
{
    public UniqueClassNumberOneProperty { get; set; }
}

class UniqueClassNumberTwo : BaseClassWithSharedProperties
{
    public UniqueClassNumberTwoProperty { get; set; }
}
roosteronacid