Often when writing code I wonder what the best way is to discriminate between types (by which I don't necessarily mean types used in typesystems). That brings up 3 questions:What is better?When is it better? What are the (dis)advantages?Using properties to discriminateclass BinaryExpression {    String operator; // e.g. +    Number lhs, rhs;}Subclassing to discriminationclass BinaryExpression {    Number lhs, rhs;}class Addition extends BinaryExpression {}// Etc.Note: I'm not sure if I have the terms right. Please correct me if I'm wrong.
Subclassing vs Using properties to discriminate types
java;inheritance
If there's a functional or operational difference between the types, then creating explicit types allows cleaner object-oriented implementations of the different functional behaviors. If the difference is just an appearance thing, then full object-orientation might be overkill (though there will be many purists who object to this pragmatic approach).For your example of operators. If you were actually using the operator class to perform calculations, then subclassing is probably the way to go (because of the differing implementations of a compute method for example). If you are simply holding the content for output serialization, then a property containing the operator character might be all you need for your purposes. 