Hands-On Design Patterns with Delphi

Book description

Get up to speed with creational, structural, behavioral and concurrent patterns in Delphi to write clear, concise and effective code

Key Features

  • Delve into the core patterns and components of Delphi in order to master your application's design
  • Brush up on tricks, techniques, and best practices to solve common design and architectural challenges
  • Choose the right patterns to improve your program's efficiency and productivity

Book Description

Design patterns have proven to be the go-to solution for many common programming scenarios. This book focuses on design patterns applied to the Delphi language. The book will provide you with insights into the language and its capabilities of a runtime library.

You'll start by exploring a variety of design patterns and understanding them through real-world examples. This will entail a short explanation of the concept of design patterns and the original set of the 'Gang of Four' patterns, which will help you in structuring your designs efficiently. Next, you'll cover the most important 'anti-patterns' (essentially bad software development practices) to aid you in steering clear of problems during programming. You'll then learn about the eight most important patterns for each creational, structural, and behavioral type. After this, you'll be introduced to the concept of 'concurrency' patterns, which are design patterns specifically related to multithreading and parallel computation. These will enable you to develop and improve an interface between items and harmonize shared memories within threads. Toward the concluding chapters, you'll explore design patterns specific to program design and other categories of patterns that do not fall under the 'design' umbrella.

By the end of this book, you'll be able to address common design problems encountered while developing applications and feel confident while building scalable projects.

What you will learn

  • Gain insights into the concept of design patterns
  • Study modern programming techniques with Delphi
  • Keep up to date with the latest additions and program design techniques in Delphi
  • Get to grips with various modern multithreading approaches
  • Discover creational, structural, behavioral, and concurrent patterns
  • Determine how to break a design problem down into its component parts

Who this book is for

Hands-On Design Patterns with Delphi is aimed at beginner-level Delphi developers who want to build scalable and robust applications. Basic knowledge of Delphi is a must.

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Hands-On Design Patterns with Delphi
  3. About Packt
    1. Why subscribe?
    2. Packt.com
  4. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Conventions used
    4. Get in touch
      1. Reviews
  6. Section 1: Design Pattern Essentials
  7. Introduction to patterns
    1. Patterns in programming
    2. Patterns are useful
      1. Delphi idioms – Creating and destroying an object
    3. Gang of Four started it all
      1. Don't inherit – compose!
    4. Pattern taxonomy
      1. Creational patterns
      2. Structural patterns
      3. Behavioral patterns
      4. Concurrency patterns
    5. Criticism
    6. Anti-patterns
    7. Design principles
      1. SOLID
      2. Don't repeat yourself
      3. KISS and YAGNI
    8. Summary
  8. Section 2: Creational Patterns
  9. Singleton, Dependency Injection, Lazy Initialization, and Object Pool
    1. Singleton
      1. NewInstance
      2. Lateral thinking
    2. Dependency injection
      1. From classes to interfaces
      2. Using a factory method
      3. Wrapping up
    3. Lazy initialization
      1. Using Spring
    4. Object pool
      1. Stock quote connection pool
    5. Summary
  10. Factory Method, Abstract Factory, Prototype, and Builder
    1. Factory method
      1. Painter
      2. Modernizing the factory method pattern
    2. Abstract factory
    3. Prototype
      1. Cloning records
      2. Cloning objects
      3. Delphi idioms – Assign and AssignTo
      4. Serialization
    4. Builder
      1. Idioms – Fluent interfaces
    5. Summary
  11. Section 3: Structural Patterns
  12. Composite, Flyweight, Marker Interface, and Bridge
    1. Composite
      1. Child management
    2. Flyweight
      1. String interning
      2. A practical example
      3. Delphi idioms – comparers and hashers
    3. Marker interface
      1. Delphi idioms – attributes
      2. Markers and attributes
    4. Bridge
      1. Bridged painting
    5. Summary
  13. Adapter, Proxy, Decorator, and Facade
    1. Selecting an appropriate structural pattern
    2. Adapter
      1. Wrapping a class
      2. Wrapping an interface
      3. Implementing a queue with a list
    3. Proxy
      1. Delphi idioms – replacing components in runtime
      2. Smart pointers
      3. Unit testing with mock objects
    4. Decorator
      1. Decorating streams
      2. Delphi idioms – helpers
    5. Facade
    6. Summary
  14. Section 4: Behavioral Patterns
  15. Nullable Value, Template Method, Command, and State
    1. Null object
    2. Template method
      1. Calculating the average value
      2. Inversion of control
    3. Command
      1. Command-based editor
        1. Creating commands
        2. Commands
        3. Invoker
        4. Client
        5. Macros
        6. Cloning
    4. State
      1. Unquoting a string
    5. Summary
  16. Iterator, Visitor, Observer, and Memento
    1. Iterator
      1. Delphi idioms – iterating with for..in
      2. Implementing custom enumerators
      3. Using an iterator interface
    2. Visitor
    3. Observer
      1. Observing with Spring
    4. Memento
    5. Summary
  17. Section 5: Concurrency Patterns
  18. Locking patterns
    1. Delphi idioms – parallel programming
    2. Lock
      1. Custom locking mechanism
    3. Lock striping
      1. Single bit locks
      2. Delphi idioms – bitwise operators
    4. Double-checked locking
    5. Optimistic locking
    6. Readers-writer lock
      1. Comparing reader-writer implementations
    7. Summary
  19. Thread pool, Messaging, Future and Pipeline
    1. Thread pool
      1. Idiosyncrasies of Delphi's TThreadPool
    2. Messaging
      1. Windows messages
      2. Queue and Synchronize
      3. Polling
    3. Future
    4. Pipeline
      1. Web spider
        1. Filter stage
        2. Downloader stage
        3. Parser stage
    5. Summary
  20. Section 6: Miscellaneous Patterns
  21. Designing Delphi Programs
    1. Event-driven programming
    2. Actions
    3. LiveBindings
    4. Form inheritance
    5. Frames
    6. Data modules
    7. Summary
  22. Other Kinds of Patterns
    1. Exceptions
      1. Reserving exceptions for abnormal conditions
      2. Name the problem, not the thrower
      3. Don't raise exceptions in destructors
      4. Exceptions should not cross API boundaries
      5. Exceptions should not cross thread boundaries
      6. Catching exceptions selectively
      7. Don't ignore exceptions
      8. Using an exception logger
      9. Simplifying try..finally
    2. Debugging
    3. Functional programming
    4. Summary
  23. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Hands-On Design Patterns with Delphi
  • Author(s): Primoz Gabrijelcic
  • Release date: February 2019
  • Publisher(s): Packt Publishing
  • ISBN: 9781789343243