unzip! unsnap! ahhhh!! our business object is naked. it is time to strip applications of complex uis and give users direct access to the business objects. the concept is simple: write behaviorally complete business model objects and use generic views and controllers. thus, if a business model object supports a public behavior, then the user has access to that behavior. so why do we need naked objects?
our simple naked objects project 【程序编程相关:Web Services Securit】
chances are you have struggled to truly understand the model-view-controller (mvc) pattern. why is this? the concepts are easy, right? the model contains the core business logic; the view is responsible for displaying a given models data; the controller controls the interactions between the model and the view, typically through event notification. of course, anyone who has worked with swing knows that the view and controller are often combined in the same component. for example, a jtable has a model, but is also both the view and controller. business logic can end up in all three layers, too, which violates the dry principle (dont repeat yourself). 【推荐阅读:Orchestrating Web Se】
package com.briancoyner.naked.addressbook; import org.nakedobjects.object.abstractnakedobject; public class person extends abstractnakedobject { // you must implement this method, which comes from the base class, before // the class compiles. well talk more about this in a bit. public title title() { return null; } }the naked objects framework requires that all naked objects implement the nakedobject interface. to keep things simple, we can extend from abstractnakedobject. the abstractnakedobject provides the base functionality that makes up a naked object, allowing us to focus on the business problem, which is creating a simple address book. any object that is "naked" can be seen by the user. we will see how to expose objects to an application later in the article. now that our person is naked, we need to add a few attributes and provide a way to modify them. this is accomplished using strict naming conventions and specific naked objects framework classes. lets add a few attributes: first name, last name, and birthdate. 【扩展信息:Troubleshooting .NET】
we are going to build a simple address book using the naked objects framework. an address book works nicely because it fits into the naked objects philosophy and, of course, it is easy to understand. you may download the example application here. our first requirement is that our address book may contain zero or more people. here is the first iteration of our naked person:
... 下一页