This is an old revision of the document!
In programming, an Object represents a real-world object such as a car, an employee or a task. Ultimately, as the real-world Object is defined in terms of software, it is translated to a Data Structure. The Object Data (see Figure 1 is categorized into Characteristic Data, Definition Data, Field Data and Operation Data.
Many DIDO Platforms refer to Object Data as Smart Contracts. These are similar too, but not the same as classes in Object-Oriented Programming (OOP) languages such as C++, Java, C#, Python, etc. In many ways, the differences are lexical in nature (i.e., Smart Contract versus Contract, method versus function, etc. However, there are some important differences which have to do with the distributed nature of DIDOs and the immutability of the field data (i.e., view and pure designators on methods.
The following discussion has to do with the more generic concept of Object Data but does include discussions of how it relates to DIDO Platforms in general and Ethereum's Solidity more specifically.
Any particular operation within an Object is generally Imperative in nature. This means that the Operations are composed of a set of statements. As the program steps through the Operation and executes each statement (i.e., instruction) the state of the Object is changed. Some statements change the values of the Field Data while others change the flow of execution through Control Flow operations (i.e., IF / ELSE IF / ELSE / ENDIF, or FOR LOOPS | WHILE LOOPS /, etc.).
As the statements are executed, the Program Counter for the Operation is also modified. Note: Rarely all the statements contained within a single operation, but relies on calling and executing other Operations. Therefore, most Operations are also considered a Procedural Language. Figure 2 provides a graphic of the difference between Imperative and Procedural Programs.
One of the interesting phenomenons about many of the DIDO Platforms, is the way they treat Operation Data. Many of the Platforms not only distribute the Field Data using Distributed Ledger or Journal, they also distribute the Operation Data in the same way (in essence, treating the software just as any other data). When changes are made to the Operation Data, a Transaction is created to be pushed to the Node Network.
A Constructor is a special group of Operators that are called when an Object is first created. In most Object-Oriented Programming (OOP) languages (i.e., C++, Java and C#, e.g.), the Constructor has the same name as the Object. It is the initial stage in the Lifecycle of Object Data (see 05_lifecycle). For example, for an Object called Vehicle, the Constructor would also be called Vehicle. The constructor is responsible for the setup of the Object: the initialization of Field Data, the allocation of memory from the Heap. For example, if there are dynamic Field Data, then the memory needed for those Fields is usually allocated from the Heap. Although Constants are generally managed and allocated by the compiler and are from the Stack, Static Field Data can be allocated from the Heap and can be set during construction. For example, the values of Field Data initialized by using initialization parameters on the Constructor or read from initialization or setup files.
There is always a default Constructor that required no parameters, however, there can be other Constructors allowing for the passing of values to be used during initialization. For example, the minimum or maximum values used for the Field Data.
Regardless of the number of Constructors, there is always a Constructor that is called when an object is created. Often the calling of a Constructor is automatic and used the default Constructor, but the programmer can use any of the Constructors defined for the Object. See: https://www.tutorialspoint.com/solidity/solidity_constructors.htm
When Data Object is deployed in Ethereum, the following occurs:
The contract is initialized using the Constructor method named: constructor()
Destructor is a special method called automatically during the destruction of an object. Actions executed in the destructor include the following:
When Data Object is destoryed in Ethereum, the following occurs:
selfdestruct() method or the deprecated suicide() method
An Accessor Method is an Operation defined by Object-Oriented Programming (OOP) providing access to Field Data. There are generally two Accessor Methods defined: get and set. In some Object-Oriented (OO) paradigms, the Accessor methods are further defined as:
Some benefits of using a Mutator Methods include:
Ethereum's Solidity View can attribute Methods as View. methods ensure they do not modify the Data Object state.
selfdestruct via callsGetter Method (i.e., Accessor Methods are by default view methods.
Ethereum's Solidity can attribute Methods as Pure.
block, tx, msg (msg.sig and msg.data can be read).revert() and require() functions to revert potential state changes if an error occurs.
An Abstract Method, or Virtual Method, are methods that are declared but have no underlying implementation (i.e., no body). The primary purpose of these methods is to form a base, template or guide for subsequent Data Objects derived from this Data Object. The derived Data Objects all have the same behavior defined by Abstract Methods of the base object. The original base Data Object is considered as Abstract or Virtual since without an implementation for these methods, the Data Object remains a “concept”.
Almost all Object-Oriented Programming (OOP) languages provide for the concept of Abstract or Virtual methods. In recent years, the concept of Virtual or Abstract Data Objects have lost favor to the use of Generics or Templates which can be instantiated for a particular type. For example, a double-linked-lst template, or a name-value pair template.
There are benefits of using Abstract Data Objects1):
| Template | The abstract Data Object enables the best way to execute the process of data abstraction by providing the developers with the option of hiding the code implementation. It also presents the end-user with a template that explains the methods involved. |
| Loose Coupling | Data abstraction in Data Object enables loose coupling, by reducing the dependencies at an exponential level. See 4.3.5.3 System Manageability Issues |
| Code Reusability | Using an abstract Data Object in the code saves time. Abstract Data Objects avoid the process of writing the same code again. |
| Abstraction | Data abstraction in Data Objects helps systems hide code complications and implementation details from Derived Classes (i.e., subclasses) aiding developers of Base Object and Derived Object to focus their attention to appropriate level. |
Doug Crescenzi 2) does an excellent job in summarizing the use of Abstract smart_contracts and Interfaces.
Ethereum allows for both Interfaces and for Abstract Contracts (i.e., Data Objects). An Abstract Smart Contract is any Smart Contract that has at least one method specified that does not have a corresponding body (implementation). This means that the Abstract Data Object acts like a Base Class, then the Derived Class MUST provide an implementation for the abstract method(s).
pragma solidity ^0.4.24;
contract Person
{ function gender() public returns (bytes32);
}
contract Employee is Person
{ function gender() public returns (bytes32)
{ return "female"; }
}
[char]New Section -- review