Getters are methods that provide access to an object’s instance variables.
By convention, getters are named by prefixing the corresponding instance variable with get
.
Most often getters just return the associated instance variable and nothing more.
Setters are methods that update the value of a particular instance variable.
By convention, setters are named by prefixing the corresponding instance variable with set
.
Most often setters just set the associated instance variable to the given value and nothing more.
Java Architect provide some facilities to create and manage Java getters and setters:
-
creation of getters and setters and their implementation code.
-
update of getters and setters and their implementation code when the model changes.
Creation of getters and setters
Being Java methods, getter and setters can be modeled by the user in a classical way, ie creating operations, adding parameters and return values, adding the code. However, as there are usually a lot of such getters and setters to create and as their code is very repetitive, this modeling task quickly becomes a real burden. Of course, as an alternative, the Java Architect round-trip capabilities could be used: simply reverse the Java code where you have manually coded the required getters and setters in your favorite IDE. However all this remains highly manual.
Java Architect features a powerful alternative to the previous manual methods. Java Architect can create the setters and getters for you with this great advantage that, once created by Java Architect, these getters and setters will be automatically updated should you later change the model. Such getters and setters when created and managed by Java Architect, will be referred to as automatic accessors in order to simplify the notation.
![]() |
Imagine that you change the name of an attribute for which automatic accessors
have been created by Java Architect. Then the automatic accessors for this attribute
will automatically be renamed in the model to follow the usual convention (getXXX() and setXXX() ).
Furthermore, the automatic accessors code will be updated as well to reflect the change in the model.
And this magical update mechanism extends to both the attribute type and cardinalities too!
|
![]() |
Java Architect will adapt the name of the getter for boolean values by generating isXXX() instead of getXXX() .
|
The creation the automatic accessors can be either:
-
left to the user’s initiative, this mode is called in user creation mode
-
carried out automatically when needed by Java Architect, this mode is called automatic creation mode.
The creation mode user or automatic can be chosen in the Java Architect parameters. See automation parameters.
In user creation mode
The user is in charge of creating the getters and setters he needs. This is easy done in the Java attributes and associations property view by choosing to have either a getter or a setter, both of them or none. The options in the property view also let you directly define the visibility of the getter/setter to create.
The following figure shows an example of an attribute property view where a getter and a setter have been configured to be protected
.

See the "Java" view for attributes and association ends to get further details.
![]() |
Remember that even when created on user’s initiative, the automatic accessors will still benefit of the automatic update when the attribute (/association) is modified in the model. |
In automatic creation mode
In this mode, the user does not have to request the creation of automatic accessors and Java Architect takes care of their creation/deletion as needed. Java Architect creates/updates the automatic accessors of an Attribute/Association according to its UML access mode value as described in the following table:
AccessMode | getter | setter |
---|---|---|
None |
No |
No |
Read |
Yes |
No |
Write |
No |
Yes |
Read Write |
Yes |
Yes |
![]() |
Beware that when you create an attribute in the model, its access mode
is set by default to None which means no getter and no setter, the
safer default choice for a better encapsulation. Remember that you can easily
change this in the "Java" view.
|
Automatic accessors visibility
When first created by Java Architect, the automatic accessors share the visibility of their related attribute/association element. For example, for a private attribute, the getter and setter initially created by Java Architect will be private too. The rationale behind this choice is that Java Architect has no legitimity to either reinforce of release the visibility of the accessors on its own because such a behavior might impact the design of the class without the user’s knowledge.
However, this 'default' visibility can always be modified by the user in the Java Architect property view and these modifications are guaranted to apply in the model and in the generated code and to be preserved by Java Architect when updating the accessors.