What is the most interesting design template you've ever met?

Most of us have already used random patterns like MVC , strategy , etc.

But for unusual problems there must be some unusual solution, and I would like to hear about it.

+7
design-patterns
source share
10 answers

Software for crashes only: http://www.usenix.org/events/hotos03/tech/full_papers/candea/candea_html/ Abstract

Programs with crash servers crash and recover quickly. There is only one way to stop such software - crashing it - and only one way to pick it up - by initiating recovery. Conflict-only systems are built from components that depend only on crash, and the use of transparent attempts at the component level hides system failures of components from the system from end users. In this article, we advocate for a design based only on glitches for Internet systems, which shows that this can lead to more reliable, predictable code and faster, more efficient recovery. We present ideas on how to create such online services, based only on failures, using successful methods to their logical extreme.

+15
source share

This is more of an anti-pattern, but I saw what I call the "Keep it all in one place" pattern. This is a great application, where all variables that were not local for each class, EVERY class, were stored in one class P (for parameters). Aside, all static variables were contained in a class called ... wait for it ... S.

In any case, some of them, this project became quite large, and suddenly nothing happened. (I was hired at this time). Surprisingly, the program did not crash, it just had a lot of side effects that made the application confused. As you can imagine, multiple threads, all accessing P and changing variables, without locks or synchronization in place.

I tell you, it was a real sight.

The company opened a new office and hired 3 people to serve it, and I was one of them. We got the program and said to fix it. We spent days sitting just clapping our eyebrows. Now, a print on my palm appeared on my face.

Other funnies ... a variable named "fudgeFactor". Still don't know what it did.

A way to get the next ascii character ...

char getNextChar(char previous) { switch (previous) case 'a': return b; case 'b': return c; ... case 'z': return a; } 

Anyway, my funny picture ... with some extra funny fun.

+5
source share

Over the past year, I have been servicing Windows applications written in LANSA, where focus control is controlled by the fact that all controls are set to tabStop = false, with the exception of two hidden buttons (PrevFocus and NextFocus). When the form loads, the focus is set in the field, and the name of this field is stored in the tracking variable (named "FocusField"). When custom tabs (or shift tabs) change focus, the GotFocus event of the corresponding button is fired. Inside this function, the case statement (select case FocusField) acts. Based on the currently focused field, the validation logic is executed and perhaps the focus changes to another field.

GotFocus events for most controls look at what the current FocusField value is and then call the LostFocus function, which works with the same case statement for FocusField so that the previously checked field is validated.

As you can probably guess, this makes it impossible to separate the user interface from the logic and incredible work to maintain. Rewriting these forms to use the simple Validate method, which checks ALL inputs and allows the usual tab properties (TabOrder, TabStop, etc.), their magic tended to reduce code by 50% and significantly more robust forms.

I have no idea where this template came from, although the RPG / green-screen programmers may have been invented by the WinForms developers who wrote the application.

+4
source share

The visitor launched me for the first time when working on a graphically-heavy program, as a very elegant way to do operations on complex structures.

besides mvc (which is not pattenr per se), it is the "king of patterns" in terms of its complexity and ability to solve problems.

+2
source share

The free interface from Fowler is a pretty interesting example. I have always had a soft spot for abstract factories, strategies, and the state model.

If I can, I recently codified a "template", which I call a "Friend Class Class" , which may be interesting or useful for restricting the visibility of private field helpers in languages ​​that do not have C ++-style friendly class classes.

+2
source share

Not much template, but dependency injection and control inversion

+2
source share

I remember when I first read about the fly pattern in GOF. A word processor is used as an example; they indicate the disadvantages of using an independent object to represent each character. The fly pattern encourages the separation of a joint, inalienable, unchanging state from an unsharp, external, mutable state. For me, at that time it was one of those "Aha!". moments that really expanded my horizons and influenced my projects to this day.

A friend of mine suggested that the strategy template is essentially a predecessor model. Many other templates (Bridge, Decorator, Proxy, State, ...) are more advanced Strategy applications. I remember how long I argued with him that there really is a difference between strategy and the state.

+2
source share

No, what about DP books and this thread are specific templates.

The translator and flies come to mind from the book "Gang 4".

I look at the powerful and deep Bridge and Mediator templates in the sw developer dashboard.

+1
source share

The most interesting design template you ever come across is the one you created yourself for obvious reasons.

Not to say that it will be the best design, just the most interesting.

0
source share

I never saw the points of the Visitor pattern until I had to directly manipulate Java bytecode using the ASM library. It's amazing how much the template simplified what would otherwise be a very difficult task.

This template is also used in most Java IDEs when you want to write your own refactoring plugin. You provide a Visitor object and are passed by AST to make any changes.

0
source share

All Articles