[Tutor] class design - base classes with optional properties?

Kent Johnson kent37 at tds.net
Fri Jan 23 01:05:44 CET 2009


On Thu, Jan 22, 2009 at 6:24 PM, Alan Gauld <alan.gauld at btinternet.com> wrote:
> "Marcus Goldfish" <magoldfish at gmail.com> wrote
>
>> I'm trying to design a base class for a hierarchy.  The properties I want
>> to
>> specify for the base class depend on the values of other properties of the
>> base class.
>
> Don't worry so much about the properties, the important thing to focus on
> in your base classes is the behaviour. What exactly will these classes do?
> What methods will they have? How will they be overridden in your
> subclasses.
>
> Ideally the properties are invisible to the users of the class so the
> interactions of the properties should all be controlled by the
> methods.

Class attributes can be a useful way to configure behaviour of
subclasses. For example an HTML rendering widget might have attributes
giving the type of tag to use to render or other HTML attributes. The
Django HTML widgets are an example of this:
http://code.djangoproject.com/browser/django/trunk/django/forms/widgets.py

Look at the Input class and subclasses.

Kent


More information about the Tutor mailing list