spencersalazar / chuck

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add constructors to class definitions

heuermh opened this issue · comments

Often state within fields of a class must be initialized properly before an instance of a class can be used by callers. Typically this initialization is performed in a constructor.

Constructor declarations
http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.8

Since ChucK does not provide constructors library authors have to rely on a pattern of static factory methods, which instantiate and return a new instance of another class. They do not prevent callers from creating instances of that class with improperly initialized fields however.

For example, the LiCK class Scales contains several static methods that instantiate and return instances of Scale.

Scales.ck, line 226
https://github.com/heuermh/lick/blob/master/Scales.ck#L226

Scales.ck, line 233
https://github.com/heuermh/lick/blob/master/Scales.ck#L233

etc.

It would be preferable to instantiate these with constructors on the subclasses of Scale themselves.