[haiku-commits] Re: haiku: hrev49568 - src/kits/interface headers/private/interface src/preferences/screen src/apps/deskbar src/apps/webpositive

  • From: "Adrien Destugues" <pulkomandy@xxxxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 24 Aug 2015 06:17:14 +0000

a0ba79fbff0d: Split BSpinner into BAbstractSpinner and...
2 concrete classes which are currently implemented:
* BSpinner (works on int32s)
* BDecimalSpinner (works on doubles)

You just introduced a new legacy class which will be thrown away once we'll
rework the interface kit.
Instead of duplicating wrong design decisions made in Be's past, why not do
some real class design for a start (ie. model/view/controller)?

I struggled with this a lot. I wanted to provide enough flexibility to
allow people to create their own kinds of spinners such as a
DateTimeSpinner or MonthSpinner without having to write too much code.
So to create a new kind of spinner you inherit from BAbstractSpinner
and then fill in the missing methods: Increment(), Decrement(),
SetValueFromText().

How would you structure this better?

Using the MVC approach as Axel suggested: A BSpinner "view" class that does
just the drawing, a "controller" class (implementing the control aspects:
changing the value, incrementing/decrementing, validating input, and keeping
the view and model in sync), and a "model" class (implements storing the data,
formatting it to a string, getting and setting values).

Devs will never have to touch the view class. They can change the data format
by changing the model, and they can change the behavior (min/max value,
increment/decrement step) by changing the controller.

Also, a BDateTimeSpinner makes no sense. You may have a BMonthSpinner and the
other fields will be integers as usual. And anyway, using spinners for his is
not a good idea, what you need is a calendar control (which we already have).

--
Adrien.

Other related posts: