ARTÍCULO
TITULO

Reliable Object Construction in Object-oriented Programming

Alexander Prutzkow    

Resumen

The construction of objects without validating the values of their fields leads to the need to introduce additional checks into the program text. The existing approaches (the Builder pattern and its modification, methods for checking the input parameters of constructors and methods) do not completely solve this problem. We introduce a design pattern for reliable object construction, which consists in adding two subsidiary classes to the original data-class. The first subsidiary class is a subclass of the data-class and has a factory method for creating objects. The parameter of this method is an object of the validator-class. Factory method is the only way to create objects. If the field values are invalid, then a default object (the Null Object pattern) is returned. The second subsidiary class is a class that validate the field values of an object of the original data-class. We demonstrate an example of reliable object construction. The advantages of the design pattern are separation of the object from its construction and parameter validation, reduction of duplication of program fragments, guaranteed object creation, no use of exceptions, null values, and nested classes.