[SciPy-User] [SciPy-user] code structure advise for a model
Christopher Barker
Chris.Barker at noaa.gov
Fri Feb 4 12:16:31 EST 2011
On 2/3/11 8:42 PM, David wrote:
> As for how to use inheritance: inheritance is tricky. One rule which
> works almost all the time to decide where B should derive from A is
> whether an instance of B can be used whenever an instance of A needs to
> be used (this is called the Liskov substitution principle if you want to
> shine in discussions).
There is also the classic way of thinking about OO:
use inheritance for a "is a" relationship:
a cat "is a" mammal.
> In that aspect, from what information you gave us, I don't see why Model
> should inherit from Params.
let's see: A Model "is a" set of parameters -- nope!
Another common relationship is the "has a" relationship:
A Model "has a" set of parameters -- yup!
So that means that your model would have a Params instance as an attribute.
> def create_params(some_param=0.0):
> data = {"some_param": some_param, "other_param": ...}
> return data
yup -- a simple dict may be all you need.
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
More information about the SciPy-User
mailing list