# Smart Contract Design Pattern for Processing Logically Coherent Transaction Types
## 3 The Pattern Design and Implementation
### Abstract Layer  
The _Abstract_ layer consists of two abstract classes: _AbstractTransaction_ and _AbstractSmartContract_. Figure 2 presents a UML Class diagram with both classes in the _Abstract_ layer of the _AdapT_ pattern.  
The _Abstract_ layer consists of two abstract classes: _AbstractTransaction_ and _AbstractSmartContract_. The _AbstractTransaction_ class serves as a parent class for all specific transaction classes handled by the specific smart contract. All specific transa  
Figure 2: Classes in the _Abstract_ layer of the _AdapT_ v2.0 pattern.  
from that abstract class, whereas the _AbstractSmartContract_ class sets a template for all specific smart contract classes. The class declares a list of verification rule objects (_rulesList_ variable). That list employs the _Predicate_ functional interface which in turn operates on reference type _AbstractSmartContract_. The class also declares a list of verification rule configurations for various types of transactions (_configurations_ variable). Such structure will enable two characteristics: handling various reference types inheriting from _Abstract Transaction_, and the use of lambda expressions for deferred execution. In addition, the _AbstractSmartContract_ class declares the _checkSC()_ method, which is used to verify the smart contract. It has one input parameter, which is a reference to the transaction object to be verified. This supports the later implementation of _pure_ type, where the result hinges only on the input data. Depending on the verification result, this method returns a _true_ or _false_ logical value. The combination of inheritance from object-oriented programming and lambda expressions from functional programming will allow for processing different types of transactions in this one method. Since they are abstract classes, none of them can be instantiated.  
Both classes from the _Abstract_ layer of the pattern were implemented in Java language. The source code of the _AbstractSmartContract_ class is shown in Listing 1.  
```
packageadapT; importjava.util.ArrayList; importjava.util.List; importjava.util.function.Predicate; publicabstractclassAbstractSmartContract{ protectedList<Predicate<AbstractTransaction>>rulesList=newArrayList<>(); protectedList<List<Predicate<AbstractTransaction>>configurations=new ArrayList<>(); publicAbstractSmartContract(){ configurations.add(newArrayList<>()); } publicbooleancheckSC(AbstractTransactiontr){ booleancorrect=false; for(Predicate<AbstractTransaction>vR:configurations.get(0)){ correct=vR.test(tr); if(!correct)break; } returncorrect; }
```  
The source code of the _AbstractTransaction_ class is shown in Listing 2.  
```
packageadapT; publicabstractclassAbstractTransaction{ }
```  
**Listing 2**. The source code of the _AbstractTransaction_ class.  
Only standard classes and interfaces available in Java language are used in the implementation. Additionally, the code is written to be domain-independent, whereas the _Concrete_ layer of the pattern uses classes implementation-specific for the concrete smart contract.