Reliable Object Construction in Object-oriented Programming

Alexander Prutzkow

Abstract


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.


Full Text:

PDF

References


H. Gerstmann, H. Diel, and W. Witzel, “The reliability of programming systems”. In C.E. Hackl (ed.) Programming Methodology. IBM 1974. Lecture Notes in Computer Science, 1975, no. 23. DOI: 10.1007/3-540-07131-8_23.

E. Gamma, R. Helm, R. Johson, J. Vlissides, Design patterns: Elements of reusable object-oriented software. Pearson Education, 1994.

S. Stelting, O. Maassen, Applied java patterns. Sun Microsystems Press, 2002.

J. Hunt, Scala Design Patterns. Patterns for practical reuse and design. Springer, 2013.

J. Bloch, Effective java, 3rd ed. Addison-Wesley, 2018.

H. Schildt, Java. The complete reference, 11th ed. McGrow-Hill Publisher, 2019.

D. Johnsson, D. Deogun, and D. Sawano, Secure by design. Manning, 2019.

Validate (Apache Commons Lang 3.12.0 API) Available: https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/Validate.html

E. Jendrock, R. Cervera-Navarro, I. Evans, D. Gollapudi, K. Haase, W. Markito, Ch. Srivathsa, The Java EE 7 tutorial, release 7 for Java EE platform. Oracle, 2013.

B. Woolf, “Null Object”. In R. Martin, D. Riehle, F. Buschmann (eds.) Pattern Languages of Program Design, 1998, no. 3, pp. 5-18.

A. Prutzkow, “Internet-resurs dlja razmeshchenija rezul'tatov nauchnoj i obrazovatel'noj dejatel'nosti” [Internet-resource for Scientific and Educational Work Result Publishing]. In Vestnik Rjazanskogo gosudarstvennogo radiotekhnicheskogo universiteta, 2018, no.63, pp. 84-89. DOI: 10.21667/1995-4565-2018-63-1-84-89. [In Rus]


Refbacks

  • There are currently no refbacks.


Abava  Кибербезопасность MoNeTec 2024

ISSN: 2307-8162