I’m referring to the pattern (aka Universal Design Pattern) as discussed in this blog post
Universal Design pattern
I guess I’m not entirely clear how to use this in practice. And how it works to accomplish operations or tasks.
In particular regarding this explanation
It’s the core API for any collection that maps names to values:
get(name) put(name, value) has(name) remove(name)
There are typically also ways to iterate over the properties, optionally with a filter of some sort.
Are the keys the name? And what are the values?
And how do you perform operations? Where are instructions for performing tasks and operations on data stored? and how are they called? Are the embedded into the ‘values’ as classes?
3
Yes, the Keys are the name or identifier of each property.
You may add a changeValue
method.
This pattern is also known a the Dynamic Object Design Pattern
.
Example (Pseudocode):
void Example()
{
KeyValueList MyControl = new KeyValueList();
MyControl->put("id", "MyControl");
MyControl->put("x", 34);
MyControl->put("y", 125);
MyControl->put("height", 200);
MyControl->put("width", 250);
MyControl->put("filled", false);
MyWindow->insertControl(MyControl);
} // void Example()
As you may check in the previous example, is common to use a list that store key value items, where there the keys are of string
types, and cannot be duplicated. The values may be stored as an type specific for each value, like integer
or logical
.
Or can be used as string
, similar to H.T.M.L. or X.M.L. attributes, like this example:
Example (Pseudocode):
void Example()
{
KeyValueList MyControl = new KeyValueList();
MyControl->put("id", "MyControl");
MyControl->put("x", "34");
MyControl->put("y", "125");
MyControl->put("height", "200");
MyControl->put("width", "250");
MyControl->put("filled", "false");
MyWindow->insertControl(MyControl);
} // void Example()
Both, cases are optional.
The example is generic, identifiers and types, can change from library or programming language.
This Design Pattern is commonly used in programming languages that are not Object Oriented, (like “functional” or “procedural”), to emulate objects.
Is also used in Programming Languages that are already Object Oriented, but, the properties are statically designed, and cannot be added or removed at execution.
Cheers.
4