[Newbies] Best practice for very simple objects

Michael Rueger m.rueger at acm.org
Tue Jun 26 13:45:26 UTC 2007


Norbert Hartl wrote:

> At first I created a lot of classes like AdminRole,
> MemberRole, CreatePermission, ModifyPermission etc.
> I used the class objects for this. These only carry
> some state like index, label. The role objects also 
> carry a set of permissions. 

I'm a big fan of instances :-)

Have one Permission class, one for Role etc.

Then you can have instance creation methods (maybe via a cache)

Permission modify, Role admin

Internally you could actually use (symbol) names

Permission>>modify

^Permission new name: #modify

or

self cache at: #modify ifAbsentPut: [...]

This would make it easier to extend the role and permission model later

Permission>>named: permissionID


> anAction requires: Modifypermission

anAction requires: Permission modify

Cheers

Michael


More information about the Beginners mailing list