Quantcast
Channel: Latest Questions by Gillissie
Viewing all articles
Browse latest Browse all 93

class design preference

$
0
0
If you were designing a class that could be used for a few different types of objects, and not every property was used for every object type how would you do it between the two versions here? Mainly, sometimes an object will always only have one "transition" value, and sometimes it will have more than one. Would you use an array even for object that only need one value, or would you use a single property for those and an array for objects that need more than one value?
class myClass
{
    public string transition;     // Use for objects that only need one value.
    public string[] transitions;  // Ignore for objects that only need one value.
    public int otherProperty;
    ...etc.
}
or
{
    public string[] transitions;  // Use when one or more values are needed.
    public int otherProperty;
    ...etc.
}

Viewing all articles
Browse latest Browse all 93

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>