Dynamic model

1. Understand the dynamic model

    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.

1.1. Everything is an object

    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.

1.2. Implementation principle

    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.

2. Object-oriented

    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.

2.1. Class

    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.

  • <thing name="Person">
    The class name is Person.
      
  • <attribute name="name">
    Person has an attribute named name.
      
  • <JavaAction name="sayHello">
    Person has a behavior called sayHello. It is agreed that under the node named actions, the first node is the definition of behavior.
      
  • <thing name="child" extends="Person>
    Person can have Child subnodes, where Child inherits Person, so Child also has a name attribute and a sayHello method.

2.2.Object

    Schematic code that uses a model to represent an object.

<Person name="Zhagnsan" descriptors="Person">
     <Child name="Xiaoming"/>
</Person>
  • <Person name="Zhangsan" descritpors="Person">
    descriptors="Person" indicates that Zhangsan's class is Person.
      
  • <Child name="Xiaoming">
    Xiaoming is a child node of Zhangsan.

2.3. The model is the program

    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.

2.4. Using models in code

    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());

3.FAQ

  • Is dynamic modeling a programming language?
    It might be better to think of dynamic models as a post-linguistic approach to programming. That is to say, the dynamic model is based on other programming languages, and the dynamic model is not suitable for writing basic functions such as algorithms. It is suitable for continuing programming in other languages and existing functions.
       
  • What basic models are there?
    The dynamic model itself only defines a basic model (meta-model), and the others are encapsulations of various functions written in Java, so the basic model is generally customized or written by others. If you use XWorker, you need to understand the model defined by XWorker.
       
  • How to get started?
    The syntax rules of dynamic models are basically reflected in the XWorker model editor. Learn how to create in the model editor , edit and run the model, and basically master the programming method of dynamic model.
       

 

 

 

Copyright ©  2007-2019 XWorker.org  版权所有  沪ICP备08000575号