Object Thinking: Nesne yönelimli dil kullanmak ile nesne yönelimli tasarım yapmak arasındaki fark

07 Jul

Dr. David West’in Object Thinking başlıklı kitabını bugün bitirdim. Başlangıçta “MS Press’ten çıkan bir kitap ne kadar teknoloji bağımsız ve derin olabilir ki?” diye önyargılı yaklaşmışsam da Dr. West beni hemen her bölümde ziyadesi ile utandırdı 😉

Nesneye yönelik programlama dillerinden birini kullanmak ile (yıllardır kullanıyor olabilirsiniz) nesneye yönelik modelleme yapmak (ve sonra bunu uygulamak) arasındaki farkı çarpıcı şekilde gösteren ve ikincisinin önemini çok sağlam şekilde anlatan kitap, nesneye yönelik düşünme alışkanlıklarına ve avantajlarına da sahip olmadan nesneye yönelik dillerin uzunca bir süre kullanılabileceğini vurguluyor.

Bu bağlamda aşağıdaki diyalog (anlayana) çok şey anlatıyor. Vocabulary: Words toThink With başlıklı beşinci bölümden (vurgular bana ait):

Forward Thinking?It?s Not a Code ?Smell,? But ?

“Every time I look at this code, it seems strange ? but not strange,” Jon comments to Samantha. “It?s pretty ordinary for the most part, but I have this constant nagging feeling that something is different ? not wrong, just different.”

“Not surprising,” replies Samantha. “This is probably your first real object-oriented project as well as your first XP project.”

“What do you mean? I?ve been writing Java for several years; doesn?t that count as OO?”

Not necessarily, because what you code is dependent on how you have thought about the problem space and how you have decomposed that space into objects. Just using a particular language doesn?t mean you build objects; only object thinking about decomposition assures that you will build objects.”


“Let me show you. Remember the ‘Serene Meditation’ story we worked on last week?”

“Yeah, our customer has some imagination when he writes story titles. ‘Serene Meditation: The machine goes into a power-save mode until a potential customer triggers an induction field around the machine or calls the machine’s published phone number. When its meditation is interrupted, the machine lights up, its selection menu is presented, and the money-accepting mechanisms are initiated.'”

“Yeah, he does, but when we first wrote the code for that story you had two ‘controller’ objects, phone and inductionField, that tried to keep track of the other components and send them wake-up messages. When I pointed out the duplicated code, you quickly refactored into a single controller, but then you had to include a case statement to notify different objects depending on the actual source of the wake-up event. Only after we talked about MVC and using event dispatchers and event registration did we hit on the correct solution: let the machine, selectionMenu, coinAccepter, billAccepter, and cardAccepter objects register with the inductionField or phone object so that it?s notified if it detects the unique event it?s looking for. When we wrote the code, it didn’t look radically different, but the organization of the code to form the methods was different.”

“And last week, we were working on the form object and had really different ideas of what its methods should be?”

“Yeah, I had a whole bunch of methods, mostly setters and getters for attributes. You had only three or four methods that you thought necessary. Turns out I was thinking about attributes all wrong.”

“Not all wrong, and according to some object theorists not wrong at all. When Coad and Yourdon published their first book on OO analysis, they defined objects and attributes as if they were standard data entities. Schlaer and Mellor, Rumbaugh, and a host of others did essentially the same thing. UML, which you used a lot before coming here, allows greater latitude in the definition of an attribute, but the base definition is still ‘a named characteristic with a value.’ You were still thinking of attributes as some characteristic of an object, the value of which the system had to remember.”

“So you were thinking of a form in terms of a lot of attributes: formNumber, dateCreated, lastRevisionDate, title, and so on. I was defining a form as an object that contained other objects, a collection, and an object that could identify itself, display itself (with help from the objects it contained), and describe itself.”

“Yeah, all the attributes I was listing ended up being inside a description object ? another kind of collection, kind of like a dictionary.”

“So you see, it?s not the code that?s different ? it?s the objects and the distribution of methods across the set of objects that’s different.”

“And the vocabulary is different too. I have to keep reminding myself that things such as functions and methods look essentially the same, but they derive from very different ideas. A method reflects a behavior expected in the domain, and a function reflects a unit of execution in the machine.”

“Got it! Now back to this ‘reorder product’ story.”

Konuyla ilgili diğer girdilerimi de not düşeyim kolay erişim için: [1], [2], [3].

1 Comment

Posted by on July 7, 2006 in General, Programlama


One response to “Object Thinking: Nesne yönelimli dil kullanmak ile nesne yönelimli tasarım yapmak arasındaki fark

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: