Object Design Style Guide

Book description

Objects are the central concept of languages like Java, Python, C#. Applying best practices for object design means that your code will be easy to read, write, and maintain. Object Design Style Guide captures dozens of techniques for creating pro-quality OO code that can stand the test of time. Examples are in an instantly familiar pseudocode, teaching techniques you can apply to any OO language, from C++ to PHP.

About the Technology
Well-written OO code is a pleasure to read, modify, and debug. Elevate your coding style by mastering the universal best practices for object design presented in this book. These clearly presented rules, which apply to any OO language, maximize the clarity and durability of your codebase and increase productivity for you and your team.

About the Book
Object Design Style Guide presents dozens of professional techniques for writing OO code. In it, veteran developer Matthias Noback lays out design rules for constructing objects, defining methods, changing and exposing state, and much more. All examples use instantly familiar pseudocode, so you can follow along in the language you prefer. You’ll go case by case as you explore important scenarios and challenges for object design and then walk through a simple web application that demonstrates how different types of objects can work together effectively.

What's Inside
  • Universal design rules for a wide range of objects
  • Best practices for testing objects
  • A catalog of common object types
  • Exercises for each chapter to test your object design skills

About the Reader
For readers familiar with an object-oriented language and basic application architecture.

About the Author
Matthias Noback is a professional web developer with nearly two decades of experience. He runs his own web development, training, and consultancy company called “Noback’s Office.”

Offers both guidelines and guidance on how to achieve a clear, consistent tone across a larger team.
- From the Foreword by Ross Tuck

Demystifies OOP and describes how to use it to design truly secure and performant applications.
- Charles Soetan, Plum.io

Extremely well-written content for all skill levels in the industry.
- Shayn Cornwell, XeroOne Systems

An objective go-to reference for programmers wanting to standardize their OOP procedures.
- Joseph T. Lyons, SYSCON International

Publisher resources

View/Submit Errata

Table of contents

  1. Copyright
    1. Dedication
  2. Brief Table of Contents
  3. Table of Contents
  4. Foreword
  5. Preface
  6. Acknowledgments
  7. About this Book
    1. Who should read this book
    2. How this book is organized: A roadmap
    3. About the code
    4. liveBook discussion forum
  8. About the Author
  9. About the Cover Illustration
  10. Chapter 1. Programming with objects: A primer
    1. 1.1. Classes and objects
    2. 1.2. State
    3. 1.3. Behavior
    4. 1.4. Dependencies
    5. 1.5. Inheritance
    6. 1.6. Polymorphism
    7. 1.7. Composition
    8. 1.8. Class organization
    9. 1.9. Return statements and exceptions
    10. 1.10. Unit testing
    11. 1.11. Dynamic arrays
    12. Summary
  11. Chapter 2. Creating services
    1. 2.1. Two types of objects
    2. 2.2. Inject dependencies and configuration values as constructor arguments
    3. 2.3. Inject what you need, not where you can get it from
    4. 2.4. All constructor arguments should be required
    5. 2.5. Only use constructor injection
    6. 2.6. There’s no such thing as an optional dependency
    7. 2.7. Make all dependencies explicit
    8. 2.8. Task-relevant data should be passed as method arguments instead o- of constructor arguments
    9. 2.9. Don’t allow the behavior of a service to change after it has been instantiated
    10. 2.10. Do nothing inside a constructor, only assign properties
    11. 2.11. Throw an exception when an argument is invalid
    12. 2.12. Define services as an immutable object graph with only a few entry points
    13. Summary
    14. Answers to the exercises
  12. Chapter 3. Creating other objects
    1. 3.1. Require the minimum amount of data needed 3.1 to behave consistently
    2. 3.2. Require data that is meaningful
    3. 3.3. Don’t use custom exception classes for invalid argument exceptions
    4. 3.4. Test for specific invalid argument exceptions by analyzing the ex- xception’s message
    5. 3.5. Extract new objects to prevent domain invariants from being verif- fied in multiple places
    6. 3.6. Extract new objects to represent composite values
    7. 3.7. Use assertions to validate constructor arguments
    8. 3.8. Don’t inject dependencies; optionally pass them as method arguments
    9. 3.9. Use named constructors
    10. 3.10. Don’t use property fillers
    11. 3.11. Don’t put anything more into an object than it needs
    12. 3.12. Don’t test constructors
    13. 3.13. The exception to the rule: Data transfer objects
    14. Summary
    15. Answers to the exercises
  13. Chapter 4. Manipulating objects
    1. 4.1. Entities: Identifiable objects that track changes and record events
    2. 4.2. Value objects: Replaceable, anonymous, and immutable values
    3. 4.3. Data transfer objects: Simple objects with fewer design rules
    4. 4.4. Prefer immutable objects
    5. 4.5. A modifier on an immutable object should return a modified copy
    6. 4.6. On a mutable object, modifier methods should be command methods
    7. 4.7. On an immutable object, modifier methods should have declarative names
    8. 4.8. Compare whole objects
    9. 4.9. When comparing immutable objects, assert equality, not sameness
    10. 4.10. Calling a modifier method should always result in a valid object
    11. 4.11. A modifier method should verify that the requested state change is valid
    12. 4.12. Use internally recorded events to verify changes on mutable objects
    13. 4.13. Don’t implement fluent interfaces on mutable objects
    14. Summary
    15. Answers to the exercises
  14. Chapter 5. Using objects
    1. 5.1. A template for implementing methods
    2. 5.2. Some rules for exceptions
    3. Summary
    4. Answers to the exercises
  15. Chapter 6. Retrieving information
    1. 6.1. Use query methods for information retrieval
    2. 6.2. Query methods should have single-type return values
    3. 6.3. Avoid query methods that expose internal state
    4. 6.4. Define specific methods and return types for the queries you want to make
    5. 6.5. Define an abstraction for queries that cross system boundaries
    6. 6.6. Use stubs for test doubles with query methods
    7. 6.7. Query methods should use other query methods, not command methods
    8. Summary
    9. Answers to the exercises
  16. Chapter 7. Performing tasks
    1. 7.1. Use command methods with a name in the imperative form
    2. 7.2. Limit the scope of a command method, and use events to perform secondary tasks
    3. 7.3. Make services immutable from the outside as well as on the inside
    4. 7.4. When something goes wrong, throw an exception
    5. 7.5. Use queries to collect information and commands to take the next steps
    6. 7.6. Define abstractions for commands that cross system boundaries
    7. 7.7. Only verify calls to command methods with a mock
    8. Summary
    9. Answers to the exercises
  17. Chapter 8. Dividing responsibilities
    1. 8.1. Separate write models from read models
    2. 8.2. Create read models that are specific for their use cases
    3. 8.3. Create read models directly from their data source
    4. 8.4. Build read models from domain events
    5. Summary
    6. Answers to the exercises
  18. Chapter 9. Changing the behavior of services
    1. 9.1. Introduce constructor arguments to make behavior configurable
    2. 9.2. Introduce constructor arguments to make behavior replaceable
    3. 9.3. Compose abstractions to achieve more complicated behavior
    4. 9.4. Decorate existing behavior
    5. 9.5. Use notification objects or event listeners for additional behavior
    6. 9.6. Don’t use inheritance to change an object’s behavior
    7. 9.7. Mark classes as final by default
    8. 9.8. Mark methods and properties private by default
    9. Summary
    10. Answers to the exercises
  19. Chapter 10. A field guide to objects
    1. 10.1. Controllers
    2. 10.2. Application services
    3. 10.3. Write model repositories
    4. 10.4. Entities
    5. 10.5. Value objects
    6. 10.6. Event listeners
    7. 10.7. Read models and read model repositories
    8. 10.8. Abstractions, concretions, layers, and dependencies
    9. Summary
  20. Chapter 11. Epilogue
    1. 11.1. Architectural patterns
    2. 11.2. Testing
    3. 11.3. Domain-driven design
    4. 11.4. Conclusion
  21. Appendix: Coding standard for the code samples
  22. Style guide cheat sheet
  23. Index
  24. List of Figures
  25. List of Tables
  26. List of Listings

Product information

  • Title: Object Design Style Guide
  • Author(s): Matthias Noback
  • Release date: January 2020
  • Publisher(s): Manning Publications
  • ISBN: 9781617296857