Sunday, January 02, 2005

Avoiding spaghetti code

Note to myself:

functions/methods should either
1) change some internal attributes;
2) return a value/object
3) change some attribute of an object created by their parent class.

They should not directly change the state of some objects that calls them. I had the following situation:
X created Y.
X created Z.
A method of X called a method of Z which was then changing the state of an attribute of Y through a pointer reference created for that purpose. Ugly.... and difficult to maintain.

No comments: