Design Pattern: What is a Design Pattern and How Do I Use Them

Tags: #<Tag:0x00007fe0635394b8>

(Rich Koshak) #1


What Is a Design Pattern (DP)

A DP is an concept borrowed from software engineering that in turn borrowed it from architecture. A DP is a general reusable solution to a common problem. But the solution is not complete. Instead it is a template that one can apply to a lot of different situations.

The DPs posted to this forum will usually include a complete solution as an example implementation of the DP. But do not assume that the DP is only applicable in that specific example context.

Finally, a DP rarely stands alone. They are often closely related to other DPs and many solutions will often include multiple DPs.

What a Design Pattern Is Not

As mentioned above, a DP is not a comprehensive example. They are a template that one can follow to solve a given class of problems one may encounter while developing Rules.

The example code that is included with the DPs may not be fully explained. The purpose of the example code is to illustrate the DP only. But since the DPs are only templates and not complete in and of themselves, the example code will necessarily include additional code.

What Should I Know to Use a DP

Because a DP is not a complete solution, the reader needs to possess a few skills in order to apply them to their situation:

  • the basics of how to define Items and use them in Rules code
  • Rule syntax
  • the ability to follow a block of Rules code and understand at a basic level what the code does
  • the ability to recognize and deal with code in a block that is not fully explained or defined in the DP text (e.g. reference to Items not defined in the current DP)
  • the ability to generalize an example to multiple situations

Current Design Patterns

EDIT: Reworking all the DPs to reflect changes in OH 2.3.

Design Pattern: Working with Groups in Rules
Design Pattern: Event Limit
Design Pattern: Separation of Behaviors
Design Pattern: Gate Keeper
Design Pattern: Do While
Design Pattern: Time Of Day
Design Pattern: Motion Sensor Timer
What are your top 3 automations
Design Pattern: Sensor Aggregation
Design Pattern: Rule Latching
Design Pattern: How to Structure a Rule
Design Patterns: Generic Is Alive
Design Pattern: Cascading Timers
Design Pattern: Proxy Item
Design Pattern: Associated Items
Design Pattern: Group Based Persistence
Design Pattern: Time Of Day
Design Pattern: Manual Trigger Detection
Best practice for small coding (Design Pattern)
Design Pattern: Unbound Item (aka Virtual Item)
Design Pattern: Encoding and Accessing Values in Rules
Design Pattern: Human Readable Names in Messages
Design Pattern: Looping Timers
Design Pattern: Expire Binding Based Timers
GDPR Compliance and NEW WEBSITE!
Design Pattern: Recursive Timers
Design Pattern: Cancel Activity
Design Pattern: DRY, How Not to Repeat Yourself in Rules DSL
Using HABMin rules in HABPanel
Design Pattern: Switch & Dimmer