Dynamic model is an abstract object-oriented programming method that uses models to represent classes, objects, behaviors, etc. The model is structured data, which can be represented using XML, JSON, etc.
The concept of dynamic model is a bit abstract, but it is actually a straightforward explanation of the concept of object-oriented programming method "everything is an object", that is, everything is an object, and objects can be represented by models. Models are data.
Since "everything is an object", how can objects represent various things? It depends on how we interpret it.
For example, the reason why an object can be used as a class is because the object has the characteristics of a class, that is, it can be used to describe the structure and behavior of an object. The same object can also be used as a behavior, as long as it can be made executable.
Although the concept of dynamic model is a bit abstract, it is actually a typical object-oriented programming method. Programming generally defines a class first, and then uses the class to instantiate objects.
Use models to represent schematic code for classes.
<thing name="Person"> <attribute name="name"/> <actions> <JavaAction name="sayHello"/> </actions> <thing name="Child" exends="Person"/> </thing>
As shown in the above code, the XML is a model that can be used as a class.
Schematic code that uses a model to represent an object.
<Person name="Zhagnsan" descriptors="Person"> <Child name="Xiaoming"/> </Person>
The model is the final program. General models can be run directly in the editor. If XWorker is set as the system global model engine, the model can also be run directly under the system. The 22-second video below demonstrates creating and running the Zhangsan model.
You can also use models in code, such as setting model properties and executing model behaviors.
import org.xmeta.Thing; import org.xmeta.World; import org.xmeta.ActionContext; //Dynamic model engine instance def world = world.getInstance(); //The model has a unique path, and the model can be obtained through the path def person = world.getThing("Person"); //Create object model through class model def zhangsan = new Thing("Person"); //Set model properties zhagnsan.put("name", "Zhangsan"); //Execute the behavior of the model, ActionContext is the execution context zhangsan.doAction("sayHello", new ActionContext());
Copyright © 2007-2019 XWorker.org 版权所有 沪ICP备08000575号