From: James Britt Date: 2004-06-30T23:49:58+09:00 Subject: Re: SOT (slightly offtopic): General OOP question Meino Christian Cramer wrote: > Hi, > > I have a general question about OOP. > > There is no problem for me to decide how arrange and design classes > _inside_ of a program but I get a "problem" regulary, when trying to > decide what to do with "things between" the program and the outside > world. > > For example: > A Ruby script should read a file and do something with its contents. > What does the "clean white rule of OOP" say: > The "physics of the file" (open(),read(),close() and the according > error handling) become a class returning an object "containing" > the Filehandle? Or the contents of that file? It depends. It sounds like this is an implementation detail; as the user of a a file-based class, I may want to ask an object if the file contains the word 'foo'. Whether the object has to go open and scan the file on disk, or already has the contents in memory, the client probably shouldn't care. But it may depend on what role or purpose this file-based object is supposed to fill. > > Other example: It may be worth trying to write unit tests to see what design arises. OO is a very useful technique for code organization, but it does not always map well to every real-world scenario; there is often no One True Way to model something. You just have to try things out to see what feels like a good fit. James