6.30. Combined entity mode

发布时间 : 2025-10-25 13:34:17 UTC      

Page Views: 9 views

The composite entity pattern (Composite Entity Pattern) is used in the EJB persistence mechanism. A composite entity is an EJB entity bean, which represents a diagram of the object. When you update a composite entity, the internal dependent objects beans are automatically updated because they are managed by the EJB entity bean. The following are the participants of the composite entity bean.

  • 组合实体(Composite Entity) -it is the primary entity bean. It can be coarse-grained, or it can contain a coarse-grained object for persistent lifecycle.

  • 粗粒度对象(Coarse-Grained Object) -this object contains dependent objects. It has its own life cycle, and it can also manage the life cycle of dependent objects.

  • 依赖对象(Dependent Object) -A dependent object is an object whose persistent life cycle depends on coarse-grained objects.

  • 策略(Strategies) -the policy represents how the composite entity is implemented.

6.30.1. Realize

As a composite entity, we will create CompositeEntity Object. CoarseGrainedObject Is a class that contains dependent objects.

CompositeEntityPatternDemo Our demo class uses the Client Class to demonstrate the use of the composite entity pattern.

组合实体模式的 UML 图

6.30.2. Step 1

Create dependent objects.

DependentObject1.java

publicclassDependentObject1{privateStringdata;publicvoidsetData(Stringdata){this.data=data;}publicStringgetData(){returndata;}} 

DependentObject2.java

publicclassDependentObject2{privateStringdata;publicvoidsetData(Stringdata){this.data=data;}publicStringgetData(){returndata;}} 

6.30.3. Step 2

Create coarse-grained objects.

CoarseGrainedObject.java

publicclassCoarseGrainedObject{DependentObject1do1=newDependentObject1();DependentObject2do2=newDependentObject2();publicvoidsetData(Stringdata1,Stringdata2){do1.setData(data1);do2.setData(data2);}publicString[]getData(){returnnewString[]{do1.getData(),do2.getData()};}} 

6.30.4. Step 3

Create a composite solid.

CompositeEntity.java

publicclassCompositeEntity{privateCoarseGrainedObjectcgo=newCoarseGrainedObject();publicvoidsetData(Stringdata1,Stringdata2){cgo.setData(data1,data2);}publicString[]getData(){returncgo.getData();}} 

6.30.5. Step 4

Create a client class that uses composite entities.

Client.java

publicclassClient{privateCompositeEntitycompositeEntity=newCompositeEntity();publicvoidprintData(){for(inti=0;i<compositeEntity.getData().length;i++){System.out.println("Data:"+compositeEntity.getData()[i]);}}publicvoidsetData(Stringdata1,Stringdata2){compositeEntity.setData(data1,data2);}} 

6.30.6. Step 5

Use Client To demonstrate the use of composite entity design patterns.

CompositeEntityPatternDemo.java

publicclassCompositeEntityPatternDemo{publicstaticvoidmain(String[]args){Clientclient=newClient();client.setData("Test","Data");client.printData();client.setData("Second Test","Data1");client.printData();}} 

6.30.7. Step 6

Execute the program and output the result:

Data: Test Data: Data Data: Second Test Data: Data1 
《地理信息系统原理、技术与方法》  97

最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。