|How to Use Objects|
Author: Holger Gast
Despite recent rumours, object-oriented programming is far from dead. A new book on the topic is partial proof of life.
Forget what you hear from the other schools of programming, objects are the best paradigm we have. Even languages and approaches that claim to be some other programming method tend to have object- oriented features. After having just read a topical take down of object- oriented programming reading Chapter 1 of this book was a breath of fresh air.
The first thing to say about this book is that, even though it appears to be and tries hard to be technology-neutral, its base is Java and Eclipse. This is not a problem, but it might cause you some disappointment if you were hoping that the book used your favorite language. It does mention other languages and other technologies as it progresses, but by far the majority of its examples are taken from the Eclipse project and you can tell that Java is uppermost in the author's mind and other languages are mentioned as a contrast.
If you have taken any course in object-oriented program then Chapter 1 will be a welcome trip down memory lane. It is full of short pithy one-sentence mottoes that sum up what you should be doing in using objects.
Objects are team players, not lone wolves
Clearly the author hasn't met the sort of objects I generally get to work with!
Objects have an identity
Yes they do, and
Objects have state.
It is so nice to find someone writing a new book not afraid to emphasize state. So many writers are embarrassed to mention state as a property of any part of a program, given how hard functional programming tries to get rid of it. State is a natural property of real world things and objects capture this idea better than any other construct and it is one huge reason for using this approach.
At the end of Chapter 1 you have been exposed to a basic course in objects including many of the Gang of Four patterns. As well as being suitable for an academic course, you could make it a page-a-day motivational reading for any team. At the end of reading this chapter, I couldn't wait to get back to coding with my perfectly named objects and methods, lightly interacting with one another and keeping their internal workings well hidden. We all know that the good intentions wouldn't last long in the real world.
For me the book could have ended at Chapter 1 and I would have been happy, but there is a Chapter 2 which goes deeper into many of the topics mentioned in the initial chapter. This is all about object structures, compound objects, encapsulation, the visitor pattern, adapter pattern, proxy pattern and so on. Chapter 3 goes further into the general topic of inheritance and abstraction. This is really a discussion of what inheritance is all about and what role it plays in design.
Part II of the book is simply titled Contracts for Objects. This elaborates on the idea that an object has to do what it says it does and the important of saying what it does. Chapter 4 introduces the idea of a contract and how this manifests itself in different aspects of the object. Chapter 5 deals with testing which can think of as "contract enforcement". Chapter 6 look in more details at the nature of contracts - design by contract, assertions, exceptions and contracts and so on.
Part III is called Events and it really doesn't belong in this book at all. Chapter 7 is an explanation of the Standard Widget Toolkit (SWT) and it goes into the design and use of this particular GUI. There are lots of general lessons to learn but it is also very specific to the SWT. Chapter 8 is about threads and threading, including problems of synchronization. Chapter 9 is about how to structure an app with a GUI. Here we meet the usual models - MV, MVC, and so on. The technology covered is JFace. The final chapter in this section is on state machines and, while good material, it seems even more out of place.
The final part of the book is called Responsibility-Driven Design and this is all about the single responsibility principle. Chapter 11 introduces this and the associated DRY and SOLID principles. Chapter 12 is about coupling and cohesion and ideas such as the Law of Demeter. A lot of this is elaboration of ideas introduced in earlier chapters. Again the examples are from Eclipse.
This would make a good textbook for a course, but it is also good enough for private or group study. It would make a good book for a team to read as a joint project just to make sure that they were literally all on the same page. There is a lot of repetition of ideas in different guises, but this isn't a huge problem. The emphasis on Java and Eclipse based technologies might either be a plus point or a problem depending on whether or not you are using them.
Not a must read, but if your faith in object-oriented programming is beginning to flag or if you never developed one then it is worth considering.
|Last Updated ( Saturday, 13 August 2016 )|