
- #Domain specific languages martin fowler rebecca parsonspdf install
- #Domain specific languages martin fowler rebecca parsonspdf software
The customers’ controllers have a distinct idle state that the system spends most of its time in. This controller is, mostly, a simple and conventional state machine, but there is a twist. (Other kinds of state machines perform actions in different places.) In this model, actions (sending of commands) occur when you enter a state. When you’re in a particular state, certain events will transition you to another state that will have different transitions on it thus a sequence of events leads you from state to state. The basic idea is that the controller can be in different states. If you haven’t come across state machines yet, they are a common way of describing behavior-not universally useful but well suited to situations like this. I can represent this sequence as a state diagram ( Figure1.1). Once these are done, the secret panel is unlocked for her to open. To open it, she has to close the door, then open the second drawer in her chest and turn her bedside light on-in either order.

She has a secret compartment in her bedroom that is normally locked and concealed. 1.1.1 Miss Grant’s ControllerĪlthough my mythical company has thousands of satisfied customers, we’ll focus on just one: Miss Grant, my favorite. I chose a gothic castle because I get bored of all the other state machine examples. A state machine makes a good example for a DSL, so I picked that first. As the controller enters a state, it can send a command message out to the network.Īt this point, I should confess that originally in my writing it was the other way around. Each sensor sends an event that can change the state of the controller.

Looking at all these cases, it emerges that a good way to think about the controller is as a state machine.

#Domain specific languages martin fowler rebecca parsonspdf install
We want to arrange things so that the company can install a new system with the minimum of effort, so it must be easy for them to program the sequence of actions into the controller. In this case, the way the controller sends and receives messages is the same across all the customers, but the sequence of events and commands differs. What we have is a family of systems that share most components and behaviors, but have some important differences. If she forgets to turn the desk light off before she opens the inner compartment, an alarm will sound.Īlthough this example is deliberately whimsical, the underlying point isn’t that unusual. She has to close a door, take a picture off the wall, turn her desk light on three times, open the top drawer of her filing cabinet-and then the closet is unlocked. Miss Smith has a secret compartment inside a locked closet inside her office. Miss Shaw turns on a tap, then opens either of her two compartments by turning on correct light. Miss Grant closes her bedroom door, opens a drawer, and turns on a light to access a secret compartment. Each customer has individual needs, but once you look at a good sampling, you will soon see common patterns. So whenever a customer buys a gothic security system, they come in and fit the building with lots of devices and a toaster with a control program written in Java.įor this example, I’ll focus on this control program. The company bought a job lot of Java-enabled toasters during the dot-com crash and is using them as the controllers.
#Domain specific languages martin fowler rebecca parsonspdf software
We also have little control devices that respond to four-character command messages-so a device can unlock a door when it hears the message D1UL.Īt the center of all this is some controller software that listens to event messages, figures out what to do, and sends command messages. For example, a sensor attached to a drawer would send the message D2OP when the drawer is opened. They come in, set up some kind of wireless network, and install little devices that send four-character messages when interesting things happen. Let’s imagine a company that decides to build security systems based on this idea. In order to find them, heroes would need to pull the candle holder at the top of stairs and tap the wall twice. Often, these films would be set in some old castle and feature secret compartments or passages.

I have vague but persistent childhood memories of watching cheesy adventure films on TV. In the next chapter I’ll try to generalize the definition into something more widely applicable. So, here I’m going to start with an example to demonstrate the different forms a DSL can take. I like to do this by showing a concrete example and following up with a more abstract definition. When I start to write, I need to swiftly explain what it is I’m writing about in this case, to explain what a domain-specific language (DSL) is.
