Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!petunia!news From: mjohnson@cosmos.acs.calpoly.edu (Mark S. Johnson) Newsgroups: comp.lang.smalltalk Subject: To Subclass or Encapsulate? (WAS: Access Methods) Message-ID: <2815b936.c65@petunia.CalPoly.EDU> Date: 24 Apr 91 16:58:30 GMT Distribution: usa Organization: Mechanical Engrg. Dept., California Poly. State U., SLO Lines: 43 I've read the access method discussion here with great interest and as a novice Smalltalker I have learned a lot. I'd like to thank Bill Voss for his extended answer to my "eyeColor" question. I think in some vague way that I already knew the answer but was having difficulty putting it into words. The bottom line for me: any objects that I build should be much more powerful and much more "active" than mere "records;" avoiding access methods will help remind me of this. I have a related style question. (The reason I have these "style" questions is that I believe that I will be slowly "growing" a series of applications in my meager spare time; therefore, "style" as it relates to the ease of maintaining and extending programs is important to me.) THE QUESTION: Say I would like to add a Vector class for mathematical calculations. I could: (1) create Vector as a subclass of Array and modify/add methods (e.g., methods to insure that the elements of a Vector were only Numbers, vector multiplication methods, etc) -OR- (2) create Vector as a subclass of Object and "encapsulate" an Array inside Vector as an instance variable. That way I could more easily protect the underlying Array from messages that I don't want it to receive. -OR- (3) ??? If these questions are too naive for this group please let me know and I'll just shut up and listen/read. Thanks to all, Mark -- Mark S. Johnson mjohnson@stn9.me.calpoly.edu (129.65.19.9)