Plain old data structures

From Seo Wiki - Search Engine Optimization and Programming Languages
Jump to navigationJump to search

Plain old data structures (PODS) are data structures that are represented only as passive collections of field values, without using encapsulation or other object-oriented features.

Plain old data structures are appropriate when there is a part of a system where it should be clearly indicated that the detailed logic for data manipulation and integrity are elsewhere. PODS are often found at the boundaries of a system, where information is being moved to and from other systems or persistent storage, and the business logic that is found in other parts of the system is not relevant. For example, PODS would be convenient for representing the field values of objects that are being constructed from external data, in a part of the system where the semantic checks and interpretations needed for true objects have not yet been applied.

A POD type in C++ is defined as either a scalar type or a POD class. POD class has no user-defined copy assignment operator, no user-defined destructor, and no non-static data members that are not themselves PODs. Moreover, POD class must be an aggregate, meaning it has no user-declared constructors, no private nor protected non-static data, no bases and no virtual functions. The standard includes statements about how PODs must behave in C++.

In certain contexts, C++ allows only POD types to be used. For example, a union in C++ cannot contain a class that has virtual functions, or nontrivial constructors or destructors. This restriction is imposed because the compiler cannot know which constructor or destructor should be called for a union. POD types can also be used for interfacing with C, which supports only PODS.

In Java, some developers consider that the PODS concept corresponds to a class with public data members and no methods. Others would use a class that has methods but only getters and setters, with no logic. Java Beans fall under the PODS concept if they do not use event handling, and do not implement additional methods beyond getters and setters.

Other structured data representations such as XML can also be used as PODS if no significant semantic restrictions are used.

Related notes

For template-based classes in C++, it is sometimes appropriate to provide a template specialization for a PODS class that can implement moving or copying more efficiently. This technique is described in Andrei Alexandrescu's Modern C++ Design.

References

See also

If you like SEOmastering Site, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...

Explore the new cs2 skin gamble website on besoccer.com for skins and free bonuses