Magic pushbutton

Uses your system voice; voice and rate in settings.

Snapshot

≈ 3 min read

Names in other languages

No names in other languages are held for this entry yet.

Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.

The magic pushbutton is a common anti-pattern in graphical user interfaces. At its core, the anti-pattern consists of a system partitioned into two parts: user interface and business logic, that are coupled through a single point, clicking the "magic pushbutton" or submitting a form of data. As it is a single point interface, this interface becomes over-complicated to implement. The temporal coupling of these units is a major problem: every interaction in the user interface must happen before the pushbutton is pressed, business logic can only be applied after the button was pressed. Cohesion of each unit also tends to be poor: features are bundled together whether they warrant this or not, simply because there is no other structured place in which to put them.

The magic pushbutton is a common anti-pattern in graphical user interfaces. At its core, the anti-pattern consists of a system partitioned into two parts: user interface and business logic, that are coupled through a single point, clicking the "magic pushbutton" or submitting a form of data. As it is a single point interface, this interface becomes over-complicated to implement. The temporal coupling of these units is a major problem: every interaction in the user interface must happen before the pushbutton is pressed, business logic can only be applied after the button was pressed. Cohesion of each unit also tends to be poor: features are bundled together whether they warrant this or not, simply because there is no other structured place in which to put them. procedure TForm1.Button1Click(Sender: TObject); var reg: TRegistry; begin reg := TRegistry.Create; try reg.RootKey := HKey_Current_User; if reg.OpenKey('\Software\MyCompany', true) then begin reg.WriteString('Filename', Edit1.Text); end; finally reg.Free; end; end; A better way to do this is to refactor the business logic (in this example storing the filename to the registry) into a separate class. type TPreferences = class private FFilename: String; procedure SetFilename(const Value: String); public property Filename: String read FFilename write SetFilename; procedure Load; procedure Save; end; and call this class Save method from the Click handler: procedure TForm1.Button1Click(Sender: TObject); begin Preferences.Save; end; procedure TForm1.Edit1Change(Sender: TObject); begin Preferences.Filename := Edit1.Text; end; ==References==

Text derived from https://en.wikipedia.org/w/index.php?oldid=1211627866 under CC BY-SA 4.0; modifications have been made.