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.

 Artículos similares

       
 
Hao Wang and Nanfeng Xiao    
In order to better utilize and protect marine organisms, reliable underwater object detection methods need to be developed. Due to various influencing factors from complex and changeable underwater environments, the underwater object detection is full of... ver más
Revista: Applied Sciences

 
Rui Zhou, Weicheng Gao, Wei Liu and Jianxun Xu    
With advantages in efficiency and convenience, analytical models using experimental inputs to predict the mechanical properties of plain-woven fabric (PWF) composites are reliable in guaranteeing the composites? engineering applications. Considering the ... ver más
Revista: Aerospace

 
Zonglei Lyu and Jia Luo    
Airport apron carries a lot of preparations for flight operation, and the advancement of its various tasks is of great significance to the flight operation. In order to build a more intelligent and easy-to-deploy airport apron operation analysis guarante... ver más
Revista: Applied Sciences

 
Qin Zhong, Yonghua Fan and Wenbin Wu    
For hypersonic-vehicle fairing separation, the reliable separation of the fairing and rapid suppression of the separation disturbance are required in scenarios where there is high dynamic pressure and there are abrupt changes in the aerodynamic shape of ... ver más
Revista: Aerospace

 
Niranjan Ravi, Sami Naqvi and Mohamed El-Sharkawy    
Object detection is a predominant challenge in computer vision and image processing to detect instances of objects of various classes within an image or video. Recently, a new domain of vehicular platforms, e-scooters, has been widely used across domesti... ver más