Passive data structure: Difference between revisions

Content deleted Content added
m fix broken links to nist.gov/dads and switch to HTTPS
Add sections and fill out refs
Line 1:
{{multiple issues|
{{more footnotes|date=March 2013}}
{{sections|date=March 2013}}
}}
 
In [[computer science]] and [[object-oriented programming]], a '''passive data structure''' ('''PDS''', not to be confused with IBM's [[partitioned data set]]s; also termed a '''plain old data structure''', or '''plain old data''' ('''POD''')), is a term for a [[Record (computer science)|record]], to contrast with objects. It 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.<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=https://xlinux.nist.gov/dads/HTML/passiveDataStruc.html |accessdate=11 September 2014}}</ref>
 
==Rationale==
Passive 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. PDSs 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 irrelevant. For example, PDS 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 are not applied yet.
 
==In C++==
A PDS type in [[C++]], or [[Plain Old C++ Object]], is defined as either a scalar type or a PDS class.<ref>{{cite book |author= Information Technology Industry Council |publisher= ISO/IEC |___location= Geneva |title= Programming languages — C++ |id= 14882:2003(E) |edition= Second |date= 2003-10-15}}</ref> A PDS class has no user-defined copy assignment operator, no user-defined destructor, and no non-static data members that are not themselves PDS. Moreover, a PDS 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 |ISBNisbn= 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 updated November 29, 1999.}}</ref> The standard includes statements about how PDS must behave in C++. The <tt>type_traits</tt> library in the [[C++ Standard Library]], provides a function named <tt>is_pod</tt> 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/ |accessdate=6 December 2016 |title=is_pod C++ Reference] |publisher=cplusplus.com}}</ref>
 
In some contexts, C++ allows only PDS 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. PDS types can also be used for interfacing with [[C (programming language)|C]], which supports only PDS.
 
==In Java==
In [[Java (programming language)|Java]], some developers consider that the PDS 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 [[Plain Old Java Object]]s (POJOs), a class that has methods but only getters and setters, with no logic, and [[Java Beans]] to fall under the PDS concept if they do not use event handling and do not implement added methods beyond getters and setters.{{Citation needed|date=February 2010}} However, POJOs and Java Beans have [[Encapsulation (computer programming)|encapsulation]], and so violate the fundamental definition of PDS.
 
In [[PHP]], associated arrays and stdClass objects can be considered PDS.