Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!abvax!iccgcc!klimas From: klimas@iccgcc.decnet.ab.com Newsgroups: comp.object Subject: Re: Object-Oriented Metrics Message-ID: <3348.27c29024@iccgcc.decnet.ab.com> Date: 20 Feb 91 20:05:07 GMT References: <2040@media01.UUCP> Distribution: comp Lines: 32 In article , drich@klaatu.lanl.gov (David O. Rich) writes: > "Assuring Good Style for Object-Oriented Programs," K. Lieberherr & I. > Holland, Northeastern University, IEEE Software (September 1989). > > 8. Conditionals on the class > If you end up having a design where decisions are made > which depend on the class, you probably are doing something > wrong. (Like (a isKindOf String) ifTrue: [ ] ifFalse: [ ]). > > I agree with you on this point. The interesting thing is that I've > been involved in some pretty heated discussion with people who argue > the exact opposite on this point. The argument is usually in the form > of "static binding" is better than "dynamic binding" since static > binding means a programmer knows exactly which method he/she is > calling and that code written under this assumption is more readable > (i.e., decisions that are made depending on the class only makes the > code more readable since it is clear what is going on). The use of case statements is a poor programming practise in OOP as it directly (and negatively) impacts code maintainability and reusability. OOP languages are supposed to support polymorphism because it has proven to be a good solution to improving reusability and maintainablility. (NOTE: For someone who is not familiar with the problem that is caused by case statements, consider that whenever a new object involved in a case comparison is created, all other tests against that object must be re-examined in the code for validity. This increases the "surface area" that a programmer must be aware of to make a change, and hence the possibility that an error might occurr.) It is my experience that the best OO programmers write the least number of case statements. We have also had contests with some of our better OO programmers to write case statement free code and it can be done without too much trouble.