Skip to Content Java Solaris Communities Partners My Sun Sun Store United States Worldwide

»  Spotlight Articles
»  Projects
»  Publications
»  People
»  Awards
»  Events
»  Downloads
»  Internships
»  Contrarian Minds
»  About Sun Labs

Factoring the bank account

Compying the parent slot (during):

After:

Factoring the bank account

Why factor? We currently have two bank account objects. If we decide to rewrite the deposit: method, and we edit the definition in one object, it will not affect the other object. We could propagate the new definition to the other object by copying and pasting, but this is tedious and error-prone if there are lots of copies. We would like to share the methods among all copies, so that a change is visible in all of them.

Making a traits object

We are going to interpose a parent object between the bank account and traits clonable. This will be the bank account's traits object. Then, we can move behavior from the bank account to its traits, so that when we have many bank accounts we can modify them all by modifying the traits.

Our new traits is to inherit from traits clonable. We already have a parent slot that refers to traits clonable, so that's a good starting point for our new object. We can copy this slot using the middle-button menu on the slot, and drop it into the background. This will cause a new object to be created containing this slot.

[ Previous ] [ Index ] [ Next ]
Would you recommend this Sun site to a friend or colleague?
Contact About Sun News Employment Privacy Terms of Use Trademarks Copyright 1994-2008 Sun Microsystems, Inc.