Alex Rivera | Logout

To implement a property or to implement a subclass

Asked 2011-05-15T13:03:42.907
16

I've got a class called List_Field that, as the name suggests, builds list input fields. These list input fields allow users to select a single item per list.

I want to be able to build list input fields that would allow users to select multiple items per list, so I have the following dilemma:

Should I do that through implementing a multiple_choice_allowed property into the existing List_Field property, or should I implement a Multiple_Choice_List_Field subclass of the List_Field class?

What's the engineering principle that I should follow when confronted with dilemmas like this one?

Edit
Report

1 Answer

1

Personally, I would say neither: instead use a constructor that takes multiple_choice_allowed, and then have a property exposing ListFields as a collection (with just one element when only one is allowed, all of them when more than one is allowed). Make it readonly (which means that you should copy it whenever you return the list).

answered 2011-05-27T23:53:20.843

Your Answer