Structural Design Patterns
Podcast: Play in new window | Download (46.8MB) | Embed
Subscribe: Apple Podcasts | Spotify | Email | RSS | More
“In software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software design.” ~ sourcemaking.com
Continuing the series on design patterns with structural design patterns. Design patterns are a way of thinking about abstract concepts in Object-Oriented Programming. Structural design patterns deal with the relationships between entities. They make it easier for objects to work together.
Episode Breakdown
-
17:44 Adapter
The adapter pattern matches the interfaces of different classes to act as a bridge between two incompatible interfaces. It is a single class to join the functionality by wraping the existing classes with a new interface.
-
20:23 Bridge
A bridge separates an object’s interface from it’s implementation. The interface then acts as a bridge between concrete classes and interface implementer classes. It goes beyond encapsulation to insulate the class.
-
23:55 Composite
Composite patterns treat a group of objects like a single object creating a tree structure of simple objects to form one complex object. An example of this is a directory that contains entries. Those entries can be directories themselves with their own entries.
-
31:50 Decorator
To add responsibility to an object dynamically use a decorator pattern. They add new functionality without altering the original structure by adding client specific embellishments of core objects through recursively wrapping the original class.
-
39:34 Facade
A single class that represents an entire subsystem is a facade. It hides the complexity and provides easy client interfaces allowing higher level interfaces to wrap a complicated system with a simpler interface. An example not mentioned in the show is the automated answering systems that redirect when calling a customer service line. The caller follows a path down branches of a tree to reach the correct department.
-
46:05 Flyweight
The flyweight pattern provides a fine-grained interface for efficient sharing by reducing the number of objects created therefore decreasing the memory footprint. It reuses already existing similar objects and replaces heavy weight widgets with light weight gadgets.
-
50:45 Private Class Data
Private class data pattern restricts the accessor/mutator access by separating data from the methods that use it. It encapsulates the class data initialization.
-
53:08 Proxy
A proxy is an object that represents another object through a surrogate or placeholder. It adds an extra level of abstraction and indirection.
IoTease: Project
Outdoor Speaker System
In this week’s IoTease BJ talks about the setup he is building for his sister’s new home. The previous owner left two outdoor Bose speakers on the deck. Originally he planned to purchase a bluetooth transmitter/receiver but learned that the ones on the market can only transmit or receive not both. The new plan is to build two bluetooth receivers with Arduino boards and a custom transmitter and receiver from a Raspberry Pi so that she will be able to send music from her phone to the speakers.
Tricks of the Trade
With private class data bear in mind when considering security that no data is really private. If something is running on your box it can get to that data. This can be dangerous if you are storing a password as an object. If you are encrypting it at the database level loaded packages can read the string with the password before it goes to the database. The visibility of private data is a construct that keeps other honest programmers from screwing up not one that keeps nefarious programmers from attacking.