Xref: utzoo comp.object:2314 comp.lang.objective-c:111 Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!uwm.edu!mrsvr.UUCP!bhairavi.uucp!chandra From: chandra@bhairavi.uucp (B. Chandramouli) Newsgroups: comp.object,comp.lang.objective-c Subject: Object Oriented Design:Scenario:Opinions Sought Message-ID: <3302@mrsvr.UUCP> Date: 26 Dec 90 19:00:30 GMT Sender: news@mrsvr.UUCP Followup-To: comp.object,comp.lang.objective-c Lines: 64 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