Content deleted Content added
+"control", link widget, link polymorphism |
|||
Line 19:
Class field has a method display() for displaying the contents of the field on a window system.
Typically one [[widget (computing)| control]] is created for each field, but the type of control should depend on the type of the field, for example a TextField should be displayed as a [[text box | textbox]] control, but a BooleanField should be displayed as a checkbox control.
To solve this, Field contains a factory method, createControl(), that is called from display() to get a control of the correct type.
Line 79:
===Descriptive names===
A factory method has a distinct name.
In many object-oriented languages, constructors must have the same name as the class they are in, which can lead to ambiguity if there is more than one way to create an object (see [[polymorphism (computer science)#Overloading | overloading]]).
Factory methods have no such constraint and can have descriptive names.
As an example, when complex numbers are created from two real numbers the real numbers can be interpreted as cartesian or polar coordinates, but using factory methods, the meaning is clear:
|