Naked Objects
Total Page:16
File Type:pdf, Size:1020Kb
software construction Editors: Andy Hunt and Dave Thomas I The Pragmatic Programmers [email protected] I [email protected] Naked Objects Richard Pawson n a recent visit to Norway, I was oriented designs. The problem is that none served the customary lunch of open- of those practices is a bad habit; each was faced sandwiches. I don’t understand deliberately designed to overcome some ex- the logic of the open-faced sand- isting problem with software engineering. wich—all the work of preparing a Let’s look at an example. The argument O sandwich, but you still have to eat it for the Model-View-Controller pattern and with a knife and fork. Perhaps the Norwe- its close-relation, the Entity-Boundary-Con- gian that brought the idea of the sandwich troller pattern is that a given business object from overseas (our British tradition holds must be viewed on different platforms, in dif- that the Earl of Sandwich invented ferent contexts, and with different visual rep- it) simply lost the key instruction: resentations. Embedding knowledge of how place another slice of bread on top to create these different views in business ob- so that you can pick it up! jects would result in bloated objects with Some Norwegians might feel heavy duplication of functionality. Using the same way about what the rest MVC or EBC, the core business objects (that of the world did to one of their is, the Model or Entity objects, respectively) great ideas: object-orientation. have no knowledge of these different presen- Looking at most so-called object- tations. Dedicated presentation objects (that oriented software, you’d think the is, the View or Boundary objects) specify designers had never heard about what will appear in each view, and know the key idea: An object should how to create the visual display and accept model some aspect of the business domain— inputs from the user. Controller objects not just its attributes and associations—but all provide the glue between the two—populat- behaviors that might be required of it. This ing the views with attributes from the busi- behavioral completeness yields a big benefit, ness objects and invoking methods on those in that changes to the business domain map objects in response to user-initiated events. simply to changes in the software. Actually, However, there is a marked tendency for many designers intend to create behaviorally Controller objects to become an explicit complete objects, but just as milk degrades representation of business tasks, managing into curds and whey and salad dressing into the optimized sequence of activities and en- oil and vinegar, their software seems almost forcing appropriate business rules. In doing inevitably to separate into process and data. so, they usurp the business objects’ natural responsibilities. The presentation objects, Separating process and data meanwhile, often mix attributes from multi- Several years ago I determined to find out ple business objects. Before long, the Entity what caused this. My research identified or Model objects become the data represen- several common practices that encourage tation, and the Controller objects become the separation of process and data in object- the process representation. 0740-7459/02/$17.00 © 2002 IEEE July/August 2002 IEEE SOFTWARE 81 SOFTWAREDEPT CONSTRUCTION TITLE generic and some of which are object specific. These actions all correspond to methods on the business object. For a Customer object, specific actions in- clude Authenticate, Communicate, and RegisterNewChild. Some ac- tions perform simple operations on that object; others initiate more com- plex transactions. Users can also initiate behaviors by dragging and dropping objects on other objects, or into specific fields within objects. Dragging a Customer instance on the Child Benefit class would cause the system to check if that customer was already claiming child benefit. If not, the system initiates a new claim by creating an instance of the Child Benefit Scheme, insert- ing a reference to the Customer object inside it, and creating a new instance of Case to track the progress of this claim. The Case owner is the object Figure 1. A prototype for a new government benefits administration representing the Officer logged into system built using Naked Objects. All user actions consist of noun- the system. (The user could also per- verb style operations on core business objects. form each action individually and in a different order). The system also portrays the busi- Naked Objects for a new system, created using ness object classes directly. A win- Robert Matthews and I designed Naked Objects, to replace their exist- dow on the left lists the six primary Naked Objects, an open-source Java- ing Child Benefit Administration sys- business object classes that constitute based framework, to discourage pro- tem. That system is now in full-scale the system. Each class icon has a cess and data separation and to en- development and is near deployment. pop-up menu of class methods. courage business system creation Although the user interface differs These are mostly generic methods, from behaviorally complete objects. slightly from that shown here, the and include Naked Objects’ key idea is to directly prototype’s principles have been faith- expose the core business objects (such fully preserved. The new architecture, I Create a new instance of this class as Customer, Product, and Order) which mimics that of the Naked Ob- I Retrieve an existing instance from to the user. All user actions consist of jects framework but is tailored to the storage invoking a behavior directly on a DSCFA’s own technical environment, I List instances of this class that business object, either by selecting an will eventually replace all of their ex- match a set of criteria icon from a pop-up menu or dragging isting core business systems. I Show any subclasses that are an object and dropping it on another. Figure 1 shows several classes of available to the user There are no top-level menus, or any business objects including Customers forms or scripts sitting on the objects. (the mother and children involved in a Because there is no other mecha- The framework is so radical that it claim), Officers, Cases, Payments, nism with which users can initiate a does not even permit the creation of Communications, and Schemes (the business action, the programmers de- dialog boxes. various legislative schemes that the veloping an application are forced to DSCFA administers—only Child encapsulate all required behavior Applying the principles of Naked Benefit is included in this prototype), with the core business objects. How- Objects which are represented as icons. Users ever, because there is a 1:1 corre- One of the first organizations to can double click on any instance to spondence between the underlying apply the design principles embodied show an expanded view, or they can object model and the user interface, in Naked Objects is the Irish govern- drag it to the desktop to create a sepa- Naked Objects can auto-generate the ment’s Department of Social, Com- rate viewer. Right clicking on any in- latter from the former. Programmers munity, and Family Affairs. Figure 1 stance, in any context, produces a pop- do not need to write any user inter- shows a screenshot from a prototype up menu of actions, some of which are face code to develop a fully working 82 IEEE SOFTWARE July/August 2002 SOFTWAREDEPT CONSTRUCTION TITLE application using Naked Objects. in real time. Most approaches to rapid countered OO, and I’ve just realized Instead, at runtime the framework’s prototyping develop only the users’ how far it is from what we’ve actually generic viewing mechanism uses view of the system. Using Naked Ob- been doing.” Java’s reflection to identify objects’ jects we are prototyping the object Naked Objects is still in its in- behaviors and makes these available model simultaneously. With Naked fancy, but it is developing rapidly. We to the user. Programmers need only Objects, the conventional notion of have much that we still want to do follow a few simple conventions the user interface simply disappears— with the framework. We are starting when writing business objects in programmers don’t even consider a to get offers of help from others who Java. The Naked Objects framework user-interface because they don’t have are catching the vision. What pleases effectively provides the View and to develop one and users talk only us most is that the framework gets Controller roles in generic form— about the objects with which they simpler with every iteration. You can the programmer writes only the deal. read more about the design princi- Model objects. ples behind Naked Objects and Most early attempts at auto-gener- New generation of business systems download the Java framework from ating a user interface from an under- A handful of commercial organiza- www.nakedobjects.org. lying model, such as some application tions have already started to use Antoine de Saint Exupery wrote generators in the 1980s, produced Naked Objects to conceive a new gen- that “In anything at all, perfection is spectacularly poor user interfaces. eration of business systems. In each of finally achieved not when there is no Naked Objects does rather better. I these projects, the organization has longer anything to add, but when would not suggest that our user inter- stated that they have never seen such there is no longer anything to take faces are in any sense optimal, but positive communication between de- away, when a body has been stripped they are remarkably expressive and velopers and users during develop- down to its nakedness.” This princi- give users a strong sense of control— ment.