
Prepared exclusively for ALESSANDRO CAROLLO What Readers Are Saying About Domain-Driven Design Using Naked Objects Over the years I have watched Dan strive to find the best ways to develop complex systems, and I’m glad he has taken this opportunity to share with you just some of his insights and experiences. As well as a champion of using the Naked Objects framework, Dan has now become one of its major contributors and committers, and I must say we are lucky to have his energy and enthusiasm directed at this project. Robert Matthews Creator, the Naked Objects framework This is a tutorial, a Naked Objects manifest, a software architecture book, and a user reference, all at the same time and combined amazingly well. You’ll find this book to be the best way of developing enterprise apps without repeating yourself. Sebastián Slutzky Software engineer, Department of Family and Social Affairs, Ireland Domain-driven design comes alive in this book, as it is demonstrated by example on every page. Furthermore, Naked Objects is shown to be the ideal support for the approach, focusing as it does on the core concepts of a system’s domain. Dan Haywood’s easy style means that the complex ideas in this book come across very clearly. Don’t just read this book...mark, learn, and inwardly digest! Andy Carmichael CEO, OpenXprocess Ltd This is a great hands-on guide to implementing domain-driven solutions using the innovative Naked Objects open source framework. Dylan Hayes Solutions architect, Deloitte Consulting Prepared exclusively for ALESSANDRO CAROLLO Dan does an excellent job of bringing domain-driven design out of the realm of theory and into practical reality. Dave Klein Author, Grails: A Quick-Start Guide This book is an excellent piece of work. It’s well written, thorough, engaging, and interesting. Eoin Woods Coauthor, Software Systems Architecture: Working with Stakeholders Using Viewpoints and Perspectives This is a must-read book for CIOs, IT architects, and developers who want to understand how to build agile IT systems. Barry Keane Senior manager, BearingPoint This book is an indispensable companion in your Naked Objects journey whether you are starting with it or you have been using it for some time. Enrique Albert-Gleiser Enterprise software engineer If you are already developing with Naked Objects or are just starting out on a new project or merely curious, buy this book! Coming from one of the main drivers in the Naked Objects community, you will get an insight to this range of technologies that is absolutely invaluable. Aidan Coughlan Independent software developer Prepared exclusively for ALESSANDRO CAROLLO Prepared exclusively for ALESSANDRO CAROLLO Domain-Driven Design Using Naked Objects Dan Haywood The Pragmatic Bookshelf Raleigh, North Carolina Dallas, Texas Prepared exclusively for ALESSANDRO CAROLLO Many of the designations used by manufacturers and sellers to distinguish their prod- ucts are claimed as trademarks. Where those designations appear in this book, and The Pragmatic Programmers, LLC was aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf and the linking g device are trademarks of The Pragmatic Programmers, LLC. Every precaution was taken in the preparation of this book. However, the publisher assumes no responsibility for errors or omissions, or for damages that may result from the use of information (including program listings) contained herein. Our Pragmatic courses, workshops, and other products can help you and your team create better software and have more fun. For more information, as well as the latest Pragmatic titles, please visit us at http://www.pragprog.com Copyright © 2009 Dan Haywood. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmit- ted, in any form, or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior consent of the publisher. Printed in the United States of America. ISBN-10: 1-934356-44-1 ISBN-13: 978-1-934356-44-9 Printed on acid-free paper. P1.0 printing, December 2009 Version: 2009-12-15 Prepared exclusively for ALESSANDRO CAROLLO Contents Preface 14 Who This Book Is For ....................... 15 How the Book Is Organized .................... 16 Case Study and Exercises ..................... 17 Conventions ............................. 18 Further Resources ......................... 18 I Tools 20 1 Getting Started 21 1.1 Understanding Domain-Driven Design .......... 21 1.2 The Essentials of DDD ................... 22 1.3 Introducing Naked Objects ................ 26 1.4 Naked Objects in About Five Minutes .......... 28 1.5 How Naked Objects Helps with DDD ........... 34 1.6 The Big Picture ....................... 37 2 Identifying the Domain Concepts 41 2.1 Introducing CarServ .................... 41 2.2 Getting Ready ........................ 43 2.3 Creating the Domain Classes ............... 45 2.4 Using Repositories to Locate Objects ........... 49 2.5 Identifying Objects to the User .............. 53 2.6 Capturing Simple Business Rules ............ 59 2.7 Providing Choices for Properties ............. 61 3 Relating Objects Together 64 3.1 Associating Objects ..................... 64 3.2 Adding Describing Concepts ................ 71 3.3 Capturing Business Rules for Collections ........ 77 Prepared exclusively for ALESSANDRO CAROLLO CONTENTS 8 4 Rapid Prototyping 80 4.1 Fixtures for Setting Up Domain Objects ......... 81 4.2 Fixtures for Setting Up the Clock ............. 84 4.3 Fixtures for Setting Up User Sessions .......... 87 4.4 Organizing Fixtures into Hierarchies ........... 91 5 Creating Behaviorally Complete Objects 95 5.1 Adding Behavior to Domain Objects ........... 96 5.2 Validating Action Arguments ............... 98 5.3 Making Actions Friendlier to Use ............. 101 5.4 Adding Finders to Repositories .............. 103 6 Implementing Business Rules 106 6.1 Validation Recap ...................... 107 6.2 Disabling Class Members ................. 110 6.3 Hiding Class Members ................... 113 6.4 Declarative Rules and the Object Life Cycle ....... 117 6.5 Validating the Entire Object ................ 120 7 Using Value Types 124 7.1 Identifying Value Types ................... 125 7.2 Pushing Business Rules onto a Value Type ....... 126 7.3 Adding a Third-Party Value Type ............. 129 7.4 Specifying Defaults and Other Characteristics ..... 137 8 Isolating Infrastructure Services 140 8.1 A Taxonomy of Services .................. 141 8.2 The Domain Object Container ............... 143 8.3 Dependency Injection .................... 145 8.4 Using Services in Fixtures ................. 146 8.5 Requirements for Writing Services ............ 147 8.6 Using Interfaces for Repositories ............. 149 8.7 Implementing a Calendar Service ............. 151 8.8 Hints and Tips for Writing Services ............ 154 II Techniques 157 9 Distributing Class Responsibilities 158 9.1 Applying Coad Colors .................... 159 9.2 Factoring Out Objects ................... 161 9.3 Balancing Responsibilities ................. 166 9.4 Representing Large Collections with Finder ....... 168 9.5 Contributing Actions from Services ............ 172 Report erratum Prepared exclusively for ALESSANDRO CAROLLO this copy is (P1.0 printing, December 2009) CONTENTS 9 10 Applying Domain Patterns 176 10.1 Type as Factory Pattern .................. 177 10.2 Knowledge Level Pattern .................. 184 10.3 Null Object Pattern ..................... 187 10.4 Role Object Pattern ..................... 189 10.5 User Peer Object Pattern .................. 194 10.6 Strategy Pattern ....................... 195 10.7 Process Object Pattern ................... 200 11 Keeping the Model Maintainable 206 11.1 Analyzing the Structure of CarServ ............ 207 11.2 Decoupling by Moving Responsibilities .......... 210 11.3 Decoupling by Introducing Interfaces .......... 212 11.4 Layering Modules ...................... 219 11.5 Decoupling by Splitting Classes .............. 221 11.6 Introducing an Application Package ........... 222 11.7 An Application Architecture Blueprint .......... 225 12 Scenario Testing 229 12.1 Writing Developer Tests .................. 230 12.2 Scenario Testing Using FitNesse ............. 235 12.3 Getting Ready to Write Scenario Tests .......... 236 12.4 Writing Scenario Tests ................... 241 12.5 Hints and Tips ........................ 249 III Practices 252 13 Developing Domain Applications 253 13.1 The Layered Architecture ................. 254 13.2 Deployment Options .................... 255 13.3 Which Option to Choose? ................. 258 13.4 Development Activities ................... 261 13.5 Configuration Management ................ 264 13.6 Working Effectively ..................... 267 14 Naked Objects as a Design Tool 271 14.1 Using Naked Objects Only in Development ....... 271 14.2 Decoupling from the Framework ............. 272 14.3 Programming Model Interaction Protocol ........ 276 14.4 Changing the Programming Model ............ 278 Report erratum Prepared exclusively for ALESSANDRO CAROLLO this copy is (P1.0 printing, December 2009) CONTENTS 10 15 Integrating with Web Frameworks 281 15.1 Deploying an Embedded Metamodel ........... 282 15.2 Integrating Layers with the Custom Presentation Option 293 16 Integrating with the Database 299 16.1 Configuring XML Persistence ............... 300 16.2 Mapping
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages413 Page
-
File Size-