The application logic section of an entity file allows to define
how the data and function fields of a given entity should be
grouped within the scope of the application-specific data
processing layer of a software system.
Object classes, as well as
transaction processing data structures and functions, should
be defined within section LOGIC. The same considerations
made for section DB apply here as well:
field collection definitions are the only
Sisendel rule applicable within section LOGIC, thus
class or transaction definitions are to be expressed
as Sisendel collections.
The following code examples have been generated by applying
two simple LOGIC molds to
sample entity
employee, one mold to produce a Java[tm] class source file,
and the other to produce a C++ class definition ".h" file.
Code Example 13 - From LOGIC.class and LOGIC.parent to "Employee.java"
|
The generated Java class is derived from collections LOGIC.class
and LOGIC.parent. Collection LOGIC.class is used to
generate Java source code as follows:
- Collection members are mapped one-to-one to Java class members on lines 28-32; due to the lack of enums in Java, field position requires also the generation of lines 21-26;
- Embedded or linked entities require the generation of import clauses (lines 15-16);
- Lines 34-80 contain the generated get and set methods for the LOGIC.class members.
Collection LOGIC.parent, whose only member is person,
is reflected on the import
clause of line 14 and on the extends clause of line 18.
|
|
Source code - File "company/LOGIC/Employee.java"
|
1 /*
2 * This Java class generated by somusar/SoProMach[tm].
3 */
4
5 package com.somusar.entdemo.company;
6
7 /**
8 * Class Employee:
9 *
10 * An employee, some related information, and the
11 * department s/he works in.
12 */
13
14 import com.somusar.entdemo.persons.Person;
15 import com.somusar.entdemo.persons.PersonInfo;
16 import com.somusar.entdemo.company.Department;
17
18 public class Employee extends Person {
19
20 // Map enum 'Position' onto an int with a set of values
21 public final int PRESIDENT = 0; // President
22 public final int VICE_PRESIDENT = 1; // Vice-president
23 public final int MANAGER = 2; // Manager
24 public final int ADMIN = 3; // Admin
25 public final int SALES_REP = 4; // Sales rep.
26 public final int ENGINEER = 5; // Engineer
27
28 private int emplId;
29 private PersonInfo info;
30 private String deptDeptId; // relationship to Department
31 private int position; // enum 'Position'
32 private double salary; // range 0-1000000
33
34 /*
35 * Get methods
36 */
37
38 public int getEmplId() {
39 return emplId;
40 }
41
42 public PersonInfo getInfo() {
43 return info;
44 }
45
46 public String getDeptDeptId() {
47 return deptDeptId;
48 }
49
50 public int getPosition() {
51 return position;
52 }
53
54 public double getSalary() {
55 return salary;
56 }
57
58 /*
59 * Set methods
60 */
61
62 public void setEmplId( int emplId ) {
63 this.emplId = emplId;
64 }
65
66 public void setInfo( PersonInfo info ) {
67 this.info = info;
68 }
69
70 public void setDeptDeptId( String deptDeptId ) {
71 this.deptDeptId = deptDeptId;
72 }
73
74 public void setPosition( int position ) {
75 this.position = position;
76 }
77
78 public void setSalary( double salary ) {
79 this.salary = salary;
80 }
81
82 }
|
|
Code Example 14 - From LOGIC.class and LOGIC.parent to "Employee.h"
|
Most of the notes about "Employee.java" also apply
to "Employee.h": in fact,
both Java and C++ are strongly based on the concepts of class
and class inheritance,
and entity files such as "employee.ef" are
language-neutral
with respect to such concepts, which are mapped to the
Sisendel concept of collection.
The generated C++ class is derived from collections LOGIC.class
and LOGIC.parent. Collection LOGIC.class is used to
generate C++ source code as follows:
- Collection members are mapped one-to-one to C++ class members on lines 47-51; the generated symbolic values for field position are shown on lines 36-43;
- Embedded or linked entities require the generation of #include directives (lines 29-30);
- Lines 55-101 contain the generated get and set methods for the LOGIC.class members.
Collection LOGIC.parent, whose only member is person,
is reflected on the #include
clause of line 28 and on the inheritance declaration of line 32.
|
|
Source code - File "company/LOGIC/Employee.h"
|
1 #ifndef __Employee__
2 #define __Employee__
3
4 /*
5 * -----------------------------------------------------------------
6 * Class Employee
7 *
8 * An employee, some related information, and the
9 * department s/he works in.
10 * -----------------------------------------------------------------
11 *
12 * [This header generated by somusar/SoProMach[tm].]
13 */
14
15
16
17 #ifndef __dummy_classes__
18 # define __dummy_classes__
19
20 /* Dummy declarations, just for compiling. */
21 class Collection { char s[100]; };
22 class Object { char s[100]; };
23
24 #endif
25
26 #include <String.h>
27
28 #include "persons/Person.h"
29 #include "persons/PersonInfo.h"
30 #include "company/Department.h"
31
32 class Employee : Person {
33
34 public:
35
36 enum enumPosition {
37 PRESIDENT = 0, // President
38 VICE_PRESIDENT = 1, // Vice-president
39 MANAGER = 2, // Manager
40 ADMIN = 3, // Admin
41 SALES_REP = 4, // Sales rep.
42 ENGINEER = 5 // Engineer
43 };
44
45 private:
46
47 int emplId;
48 PersonInfo info;
49 String deptDeptId; // relationship to Department
50 enumPosition position; // enum 'Position'
51 double salary; // range 0-1000000
52
53 public:
54
55 /*
56 * Get methods
57 */
58
59 int getEmplId() {
60 return emplId;
61 }
62
63 PersonInfo getInfo() {
64 return info;
65 }
66
67 String getDeptDeptId() {
68 return deptDeptId;
69 }
70
71 enumPosition getPosition() {
72 return position;
73 }
74
75 double getSalary() {
76 return salary;
77 }
78
79 /*
80 * Set methods
81 */
82
83 void setEmplId( int emplId ) {
84 this->emplId = emplId;
85 }
86
87 void setInfo( PersonInfo info ) {
88 this->info = info;
89 }
90
91 void setDeptDeptId( String deptDeptId ) {
92 this->deptDeptId = deptDeptId;
93 }
94
95 void setPosition( enumPosition position ) {
96 this->position = position;
97 }
98
99 void setSalary( double salary ) {
100 this->salary = salary;
101 }
102
103 };
104
105 #endif /* __Employee__ */
|
|
[Previous chapter]
[Next chapter]
[Back to top]
|