Passive data structure: Difference between revisions

Content deleted Content added
m Joffan moved page Plain old data structure to Passive data structure: real descriptive name as opposed to "nickname"
 
(40 intermediate revisions by 33 users not shown)
Line 1:
{{Short description|Another term for record}}
{{multiple issues|
{{confused|Partitioned data set}}
{{more footnotes|date=March 2013}}
In [[computer science]] and [[object-oriented programming]], a '''plain oldpassive data structure''' ('''PODSPDS'''), also termed a '''plain old data structure''' or '''plain old data''' ('''POD'''), is a term for a [[Recordrecord (computer science)|record]], toin contrast with objects. That is, a PODSIt is a [[data structure]] that is represented only as passive collections of [[Fieldfield (computer science)|field]] values ([[instance variable]]s), without using [[object-oriented]] features. In [[computer science]], this is known as '''passive data structure'''.<ref name ="psd">{{cite journal |last=Black |first=Paul E. |author2=Vreda Pieterse |title=passive data structure |journal=Dictionary of Algorithms and Data Structures |year=2007 |url=httphttps://wwwxlinux.nist.gov/dads/HTML/passiveDataStruc.html |accessdate=11 September 2014}}</ref>
{{sections|date=March 2013}}
}}
 
==Rationale==
In [[object-oriented programming]], '''plain old data structure''' ('''PODS'''), or '''plain old data''' ('''POD''') is a term for a [[Record (computer science)|record]], to contrast with objects. That is, a PODS is a [[data structure]] that is represented only as passive collections of [[Field (computer science)|field]] values ([[instance variable]]s), without using [[object-oriented]] features. In [[computer science]], this is known as '''passive data structure'''.<ref name ="psd">{{cite journal|last=Black|first=Paul E.|author2=Vreda Pieterse |title=passive data structure|journal=Dictionary of Algorithms and Data Structures|year=2007|url=http://www.nist.gov/dads/HTML/passiveDataStruc.html|accessdate=11 September 2014}}</ref>
Plain oldPassive 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. PODSsPDSs are often found at the boundaries of a system, where information is being moved to and from other systems or persistent storage and the problem ___domain logic that is found in other parts of the system is not relevantirrelevant. For example, PODSPDS 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 valid objects haveare not yet been applied yet.
 
==In C++==
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. PODSs are often found at the boundaries of a system, where information is being moved to and from other systems or persistent storage and the problem ___domain 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 valid objects have not yet been applied.
A PODSPDS type in [[C++]], or [[Plain Old C++ Object]], is defined as either a scalar type or a PODSPDS class.<ref>{{cite book | author = Information Technology Industry Council | publisher = ISO/IEC | ___location = Geneva | title = Programming languages — C++ | id = 14882:2003(E) | edition = Second edition | date = 2003-10-15 }}</ref> A PODSPDS class has no user-defined copy assignment operator, no user-defined destructor, and no non-static data members that are not themselves PODSPDS. Moreover, a PODSPDS class must be an aggregate, meaning it has no user-declared constructors, no private nor protected non-static data, no virtual base classes{{efn|A PDS class can have a base class whose first non-static data members differs.<ref>{{cite book |author= Bjarne Stroustrup |publisher= Pearson Education, Inc |___location= United States of America |title= The C++ programming language |isbn= 978-0-321-56384-2 |edition= Fourth |date= June 2013}}</ref>}} and no virtual functions.<ref>[{{cite web |url=http://www.fnal.gov/docs/working-groups/fpcltf/Pkg/ISOcxx/doc/POD.html "|accessdate=6 December 2016 |title=C++ Language Note: POD Types"], by |author=Walter E. Brown, |publisher=[[Fermi National Accelerator Laboratory]], |date=September 29, 1999; last|archive-url=https://web.archive.org/web/20161203130543/http://www.fnal.gov/docs/working-groups/fpcltf/Pkg/ISOcxx/doc/POD.html updated|archive-date=3 NovemberDecember 29,2016 1999.|url-status=dead }}</ref> The standard includes statements about how PODSPDS must behave in C++. The <ttcode>type_traits</ttcode> library in the [[C++ Standard Library]], provides a functiontemplate known asnamed <ttcode>is_pod</ttcode> that can be used to determine whether a given type is a POD.<ref>[{{cite web|url=http://www.cplusplus.com/reference/type_traits/is_pod/ is_pod|accessdate=6 &mdash;December 2016 |title=is_pod C++ Reference] |publisher=cplusplus.com}}</ref> In C++20 the notion of “plain old data” (POD) and by that <code>is_pod</code> is deprecated and replaced with the concept of “trivial” and “standard-layout” types.<ref>{{Cite web|url=http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0767r1.html|title=P0767R1: Deprecate POD|website=www.open-std.org|access-date=2020-01-20}}</ref>
 
In certainsome contexts, C++ allows only PODSPDS types to be used. For example, a <ttcode>union</ttcode> in C++98 cannot contain a class that has [[virtual function]]s or nontrivial constructors or destructors. This restriction is imposed because the compiler cannot determine which constructor or destructor should be called for a union. PODSPDS types can also be used for interfacing with [[C (programming language)|C]], which supports only PODSPDS.
A PODS type in [[C++]] is defined as either a scalar type or a PODS class.<ref>{{cite book | author = Information Technology Industry Council | publisher = ISO/IEC | ___location = Geneva | title = Programming languages — C++ | id = 14882:2003(E) | edition = Second edition | date = 2003-10-15 }}</ref> A PODS class has no user-defined copy assignment operator, no user-defined destructor, and no non-static data members that are not themselves PODS. Moreover, a PODS class must be an aggregate, meaning it has no user-declared constructors, no private nor protected non-static data, no base classes and no virtual functions.<ref>[http://www.fnal.gov/docs/working-groups/fpcltf/Pkg/ISOcxx/doc/POD.html "C++ Language Note: POD Types"], by Walter E. Brown, [[Fermi National Accelerator Laboratory]], September 29, 1999; last updated November 29, 1999.</ref> The standard includes statements about how PODS must behave in C++. The <tt>type_traits</tt> library in the [[C++ Standard Library]], provides a function known as <tt>is_pod</tt> that can be used to determine whether a given type is a POD.<ref>[http://www.cplusplus.com/reference/type_traits/is_pod/ is_pod &mdash; C++ Reference]</ref>
 
==In Java==
In certain contexts, C++ allows only PODS types to be used. For example, a <tt>union</tt> in C++98 cannot contain a class that has [[virtual function]]s or nontrivial constructors or destructors. This restriction is imposed because the compiler cannot determine which constructor or destructor should be called for a union. PODS types can also be used for interfacing with [[C (programming language)|C]], which supports only PODS.
In [[Java (programming language)|Java]], some developers consider that the PODSPDS concept corresponds to a class with public data members and no methods (Java Code Conventions 10.1),[<ref name=Oracle>{{cite web|url=http://www.oracle.com/technetwork/java/codeconventions-137265.html#177] |accessdate=6 December 2016 |title=Java Code Conventions 10.1 |publisher=Oracle}}</ref> i.e., a [[data transfer object]].<ref>[{{cite web|url=http://www.oracle.com/technetwork/java/codeconventions-137265.html#177 "|title=Java Language Data Structures"], |accessdate=6 December 2016 |publisher=Sun/Oracle Code Conventions from |date=April 20, 1999.}}</ref> Others would also include [[POJOPlain old Java object]]s (POJOs), a class that has methods but only getters and setters, with no logic), and [[Java BeansJavaBeans]] to fall under the PODSPDS concept if they do not use event handling and do not implement additionaladded methods beyond getters and setters.{{Citation needed|date=February 2010}} However, [[POJO]]sPOJOs and [[Java Beans]] do have [[encapsulation (computer programming)|encapsulation]], and so violate the fundamental definition of PODSPDS.
 
Records (introduced in Java 16, in 2021) are shallowly immutable carriers of data without encapsulation, and therefore they can also be considered PDS.
In [[Java (programming language)|Java]], some developers consider that the PODS concept corresponds to a class with public data members and no methods (Java Code Conventions 10.1),[http://www.oracle.com/technetwork/java/codeconventions-137265.html#177] i.e., a [[data transfer object]].<ref>[http://www.oracle.com/technetwork/java/codeconventions-137265.html#177 "Java Language Data Structures"], Sun/Oracle Code Conventions from April 20, 1999.</ref> Others would also include [[POJO]]s (a class that has methods but only getters and setters, with no logic) and [[Java Beans]] to fall under the PODS concept if they do not use event handling and do not implement additional methods beyond getters and setters.{{Citation needed|date=February 2010}} However, [[POJO]]s and [[Java Beans]] do have encapsulation and so violate the fundamental definition of PODS.
 
==In other languages==
In [[PHP]], associatedassociative arrays and <code>stdClass</code> objects can be considered PODSPDS.{{citation needed|date=September 2019}}
 
Other structured data representations such as [[XML]] or [[JSON]] can also be used as a PODSPDS if no significant semantic restrictions are used.
 
In [[Python (programming language)|Python]], dataclass module provides dataclasses - often used as behaviourless containers for holding data, with options for data validation. The dataclasses in Python, introduced in version 3.7, that provide a convenient way to create a class and store data values. The data classes use to save our repetitive code and provide better readability.<ref>{{cite web | url=https://djtechnews.in/what-are-dataclasses-in-python/ | title=What are Dataclasses in Python? - DJTECHNEWS | date=30 August 2023 }}</ref>
==References==
 
{{reflist}}
In [[C (programming language)|C]], structs are used in the same manner.
 
==See also==
* [[Plain Oldold C++CLR Objectobject]]
 
* [[Plain Old Java Object]]
==Notes==
* [[Plain Old CLR Object]]
{{notelist}}
 
==References==
{{Reflist}}
 
[[Category:C++]]