Fixed property

from Wikipedia, the free encyclopedia

Fixed Property is an analysis model based on Martin Fowler . It describes the most common way how properties of an object are modeled.

Every object has object properties which contain information about the object and thereby classify it. There are many ways to model these properties. The most common use of fixed attributes is found. With this type of implementation, the attributes are declared in the class (object-oriented programming) and defined by their name and the return type.

use

These properties are initialized via the constructor of the class. Operations (methods) are available at runtime to either query or change information about the object. These methods are often referred to as get and set methods.

Class diagram: A person modeled with fixed properties .
class Person {
  public Date getGeburtsdatum();
  public Integer getAlter();
  public Quantity getHeight();
  public Company getArbeitgeber();
  void setGeburtsdatum(Date neuesGeburtsdatum);
  void setArbeitgeber(Company neuerArbeitgeber);
}

The example on the right is a UML model of the Person type. The source code above shows part of the Java implementation of this object. The following attributes are modeled in person: date of birth of type Date, age of type Integer and height of type Quantity.

Quantity is also an analysis sample from Martin Fowler. This is used when it comes to measurable values ​​with “amount” and “unit”.

Another attribute of person is employer. This was modeled via the association to the Company object. The implementation shows methods for changing and getting the information. These can be stored or calculated values. In this example

  • public Date getDateOfBirth(); = saved value
  • public int getAge(); = calculated value

Only set methods are offered for attributes that are required or required. For example, in the code example above, an operation to change the age is missing. This is also not necessary, as it can easily be calculated using the date of birth and this reduces the susceptibility to incorrect entries.

Advantages and disadvantages

Advantage: Fixed properties are easy to implement, and there are defined interfaces with which you can access the attributes.

Disadvantage: Fixed properties can only be defined in the design phase.

Others

In most applications with few attributes that can be managed, fixed properties are completely sufficient. If the number of attributes increases sharply or if they change often (also during runtime), fixed properties become increasingly inflexible. In these special applications, patterns such as Dynamic Property or Flexible Dynamic Property by Martin Fowler are ideal.

Web links