Class for different purposes

I have a class that is used by two different processes with each process using different properties of the class. Every time a process requires a new property, I just add it to the class. It is a bad idea? Should I just create two separate classes and update them as needed?

NB From time to time the same property is used by both processes and each process uses a different instance of the class.

+1


source to share


3 answers


General properties can be stored in one class. Then you can get two different classes from the general class and add specific properties.



+6


source


"Shared properties can be stored in one class. Then you can get two different classes from a common class and add specific properties" - Kirtan Gore



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; }
}

      

+1


source


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

0


source







All Articles