Xref: utzoo comp.object:2344 comp.lang.objective-c:137 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!hsi!stpstn!lerman From: lerman@stpstn.UUCP (Ken Lerman) Newsgroups: comp.object,comp.lang.objective-c Subject: Re: Object Oriented Design:Scenario:Opinions Sought Message-ID: <5955@stpstn.UUCP> Date: 27 Dec 90 20:09:15 GMT References: <3302@mrsvr.UUCP> Reply-To: lerman@stpstn.UUCP (Ken Lerman) Organization: The Stepstone Corporation, Sandy Hook, CT 06482 Lines: 91 In article <3302@mrsvr.UUCP. chandra@bhairavi.uucp (B. Chandramouli) writes: .This is meant for the philosophically inclined :=) . .I guess many of you would have run into the following situation. . .Scenario: (This is a little bit long but I promise to keep it as easy . reading as possible). . .A class has two instance variables. Let us call them INV1 and INV2. . .The main objective of the instances of this class are to take the value from .INV1 and put it on a screen location identified by INV2. .This method to accomplish this simple task looks like this (Pardon the .Smalltalk/Objective-C ish notation) : . . -refresh { . [userInterfaceManager at:INV2 put:INV1]; . } . .(userInterfaceManager is the all capable UIMS) . .If there are 20 such screen locations, there will be 20 instances of .this class. . .The program is working fine but one fine morning the requirements changed. . . "For just one screen location X, if the value is "PANIC", then . in addition to putting up the value, display it in reverse video." . .There are two choices: . .1) Create a subclass and override "refresh" and just create one instance . of this class to manage Screen Location X. . . -refresh { . if (INV1 == "PANIC") { . [userInterfaceManager at:INV2 put:INV1]; . [userInterfaceManager at:INV2 action:REVERSEVIDEO]; . } . } . .2) Or, modify the refresh of the existing class as follows, such that . the new behavior applies only for that screen location (i.e exectued . only by the instance responsible for that screen location). . . -refresh { . . // Check if this instance controls screen location X . if (INV2 == X) { . if (INV1 == "PANIC") { . [userInterfaceManager at:INV2 put:INV1]; . [userInterfaceManager at:INV2 action:REVERSEVIDEO]; . } . } . } . .Now my questions: . .1) Which is better and why? . .2) Which is more object oriented? . .Thanks. . .chandra Alternative 3) Subclass adding a new instance variable: panicLocation -refresh { if(INV2 == panicLocation) { [userInterfaceManager at:INV2 put:INV1]; [userInterfaceManager at:INV2 action:REVERSEVIDEO]; } } Then when an instance is created set the panicLocation appropriatly. This lets you have multiple panic locations. I don't like the second solution because it creates a class which is too specific for reuse. The second solution is not general enough. All of the should be liberally sprinkled with IMHOs. The specific context can be very important. As can the schedule and the present state of affairs. :-) Ken