using naked objects - gbv

5
Using Naked Objects . •• Dan Haywood The Pragmatic Bookshelf Raleigh, North Carolina Dallas, Texas

Upload: others

Post on 11-May-2022

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Using Naked Objects - GBV

Using Naked Objects . • • •

Dan Haywood

The Pragmatic Bookshelf Raleigh, North Carolina Dallas, Texas

Page 2: Using Naked Objects - GBV

Contents Preface xv

Who This Book Is For xvi How the Book Is Organized xvii Case Study and Exercises xviii Conventions xix Further Resources xix

I Tools 1

1 Getting Started 3 1.1 Understanding Domain-Driven Design 3

\. 1.2 The Essentials of DDD 4 1.3 Introducing Naked Objects 8 1.4 Naked Objects in About Five Minutes 10 1.5 How Naked Objects Helps with DDD 16 1.6 The Big Picture 19

2 Identifying the Domain Concepts 23 2.1 Introducing CarServ 23 2.2 Getting Ready 25 2.3 Creating the Domain Classes 27 2.4 Using Repositories to Locate Objects 31 2.5 Identifying Objects to the User 35 2.6 Capturing Simple Business Rules 41 2.7 Providing Choices for Properties 43

3 Relating Objects Together 47 3.1 Associating Objects 47 3.2 Adding Describing Concepts 54 3.3 Capturing Business Rules for Collections 60

Page 3: Using Naked Objects - GBV

Rapid Prototyping 63 4.1 Fixtures for Setting Up Domain Objects 64 4.2 Fixtures for Setting Up the Clock 67 4.3 Fixtures for Setting Up User Sessions 70 4.4 Organizing Fixtures into Hierarchies 74

Creating Behaviorally Complete Objects 79 5.1 Adding Behavior to Domain Objects 80 5.2 Validating Action Arguments 82 5.3 Making Actions Friendlier to Use 85 5.4 Adding Finders to Repositories 87

Implementing Business Rules 91 6.1 Validation Recap 92 6.2 Disabling Class Members 95 6.3 Hiding Class Members 98 6.4 Declarative Rules and the Object Life Cycle 102 6.5 Validating the Entire Object 105

Using Value Types 109 7.1 Identifying Value Types 110 7.2 Pushing Business Rules onto a Value Type I l l 7.3 Adding a Third-Party Value Type 114 7.4 Specifying Defaults and Other Characteristics 122

Isolating Infrastructure Services 125 8.1 A Taxonomy of Services 126 8.2 The Domain Object Container 128 8.3 Dependency Injection 130 8.4 Using Services in Fixtures 131 8.5 Requirements for Writing Services 132 8.6 Using Interfaces for Repositories 134 8.7 Implementing a Calendar Service 136 8.8 Hints and Tips for Writing Services 139

Techniques 143 Distributing Class Responsibilities 145 9.1 Applying Coad Colors 146 9.2 Factoring Out Objects 148 9.3 Balancing Responsibilities 152 9.4 Representing Large Collections with Finder 155 9.5 Contributing Actions from Services 158

Page 4: Using Naked Objects - GBV

^ ix

10 Applying Domain Patterns 163 10.1 Type as Factory Pattern 164 10.2 Knowledge Level Pattern 170 10.3 Null Object Pattern 173 10.4 Role Object Pattern 175 10.5 User Peer Object Pattern 180 10.6 Strategy Pattern 181 10.7 Process Object Pattern 186

11 Keeping the Model Maintainable 193 11.1 Analyzing the Structure of CarServ 194 11.2 Decoupling by Moving Responsibilities 197 11.3 Decoupling by Introducing Interfaces 199 11.4 Layering Modules 206 11.5 Decoupling by Splitting Classes 208 11.6 Introducing an Application Package 209 11.7 An Application Architecture Blueprint 212

12 Scenario Testing 217 12.1 Writing Developer Tests . . 218 12.2 Scenario Testing Using FitNesse 223 12.3 Getting Ready to Write Scenario Tests 224 12.4 Writing Scenario Tests 229 12.5 Hints and Tips 236

III Practices 239

13 Developing Domain Applications 241 13.1 The Layered Architecture 242 13.2 Deployment Options 243 13.3 Which Option to Choose? 246 13.4 Development Activities 249 13.5 Configuration Management 252 13.6 Working Effectively 255

14 Naked Objects as a Design Tool 259 14.1 Using Naked Objects Only in Development 259 14.2 Decoupling from the Framework 260 14.3 Programming Model Interaction Protocol 264 14.4 Changing the Programming Model 266

Page 5: Using Naked Objects - GBV

x • CONTENTS

15 Integrating with Web Frameworks 269 15.1 Deploying an Embedded Metamodel 270 15.2 Integrating Layers with the Custom Presentation Option 281

16 Integrating with the Database 287 16.1 Configuring XML Persistence 288 16.2 Mapping Entities Using JPA Annotations 290 16.3 Mapping Value Objects Using JPA Annotations 296 16.4 Mapping Relationships 298 16.5 Porting over Repositories 302 16.6 Deploying and Running the Application 305

17 Integrating Within the Enterprise 311 17.1 Bounded Context Patterns 312 17.2 Exposing a RESTful Web Service for Other Systems . . 314 17.3 Integrating Using an Enterprise Service Bus 320

18 Deploying the Full Runtime 333 18.1 Deploying the Application 333 18.2 Securing the Application 342 18.3 Deploying the Sister Projects 347 18.4 A CarServ Retrospective 352 18.5 The DSFA Application 353 18.6 Closing Thoughts 354

IV Appendixes 3 6 3

A Programming Model Cheat Sheet 365

В Eclipse Templates 369

С Bibliography 373

Index 377