QFramework
latest

Introduction

  • QFramework Intro
  • Roadmap

QFramework v1.0 Guide: Introduction

  • 01. Project Introduction
  • 01. Introduction
  • 02. Roadmap

QFramework v1.0 Guide: Architecture

  • 01. Introduction to QFramework Architecture
  • 02. MVC in QFramework
  • 03. Introduction to Command
  • 04. Introduction to Event
  • 05. Introduction to Utility
  • 06. Introduction to System
  • 08. Designing Modules with Interfaces (Dependency Inversion Principle)
  • 09. Introduction to Query
  • 10. Architecture Specification and Recommended Usage
    • Summary
  • 11. Speedy Implementation of EditorCounterApp and Development Mode for Main Programmers
  • 12. Paper Design
  • 13. Benefits of Architecture
  • 14. Command interception
  • 15. Built-in Tool: TypeEventSystem
  • 16. Built-in Tool: EasyEvent
  • 17. Built-in Tool: BindableProperty
  • 18. Built-in Tool: IOCContainer
  • 19. Architecture in Mind
  • 20. More about QFramework.cs

QFramework v1.0 Guide: Toolkits

  • 01. Introduction to QFramework.Toolkits
  • 02. Download and Installation
  • 03. CodeGenKit Script Generation
  • 04. ActionKit Sequential Action Execution System
  • 05. ResKit Resource Management & Development Solution
  • 06. UI Kit Interface Management & Rapid Development Solution
  • 07. AudioKit Audio Management Solution
  • 08. FluentAPI Chain API
  • 09. SingletonKit Singleton Template Kit
  • 10. FSMKit State Machine
  • 11. PoolKit Object Pooling Kit
  • 12. TableKit Table Data Structure
  • 13. Other Event Tools
  • 14. More Content
  • 15. Additional Content: GridKit Two-Dimensional Grid Data Structure
  • 16. Additional Content: LiveCodingKit - A Powerful Tool for Coding on the Fly
QFramework
  • 10. Architecture Specification and Recommended Usage
  • Edit on GitHub

10. Architecture Specification and Recommended Usage

The QFramework architecture provides four levels:

  • Presentation layer: IController

  • System layer: ISystem

  • Data layer: IModel

  • Utility layer: IUtility

In addition to the four levels, concepts and tools such as Command, Query, Event, and BindableProperty are also provided.

Here are some rules for the levels:

  • Presentation layer: ViewController layer. IController interface, responsible for the presentation when receiving input and state changes. In general, MonoBehaviour is the presentation layer.

    • Can get System, Model

    • Can send Command, Query

    • Can listen to Event

The interface definition of Controller is as follows:

#region Controller
public interface IController : IBelongToArchitecture, ICanSendCommand, ICanGetSystem, ICanGetModel,ICanRegisterEvent, ICanSendQuery
{
}

#endregion
  • System layer: System layer. ISystem interface, helps IController to bear some logic, such as timing system, mall system, achievement system, etc., shared by multiple presentation layers.

    • Can get System, Model

    • Can listen to Event

    • Can send Event

The interface definition of System is as follows:

#region System
public interface ISystem : IBelongToArchitecture, ICanSetArchitecture, ICanGetModel, ICanGetUtility,ICanRegisterEvent, ICanSendEvent, ICanGetSystem
{
    void Init();
}
  • Data layer: Model layer. IModel interface, responsible for defining data and providing methods for data addition, deletion, modification, and query.

    • Can get Utility

    • Can send Event

The interface definition of Model is as follows:

public interface IModel : IBelongToArchitecture, ICanSetArchitecture, ICanGetUtility, ICanSendEvent
{
    void Init();
}
  • Utility layer: Utility layer. IUtility interface, responsible for providing infrastructure, such as storage methods, serialization methods, network connection methods, Bluetooth methods, SDK, framework inheritance, etc. Can’t do anything, can integrate third-party libraries or encapsulate APIs.

The interface definition of Utility is as follows:

#region Utility
public interface IUtility
{
}

#endregion
  • Command: Command, responsible for data addition, deletion, and modification.

    • Can get System, Model

    • Can send Event, Command

The interface definition of Command is as follows:

public interface ICommand : IBelongToArchitecture, ICanSetArchitecture, ICanGetSystem, ICanGetModel, ICanGetUtility,ICanSendEvent, ICanSendCommand, ICanSendQuery
{
    void Execute();
}
  • Query: Query, responsible for data query.

    • Can get System, Model

    • Can send Query

public interface IQuery<TResult> : IBelongToArchitecture, ICanSetArchitecture, ICanGetModel, ICanGetSystem,ICanSendQuery
{
    TResult Do();
}
  • General rules:

    • IController must use Command to change the state of ISystem and IModel.

    • After the state of ISystem and IModel changes, notify IController using events or BindableProperty.

    • IController can obtain ISystem and IModel objects for data queries.

    • ICommand and IQuery cannot have states.

    • The upper layer can directly obtain the lower layer, and the lower layer cannot obtain the upper layer object.

    • Use events for communication from the lower layer to the upper layer.

    • Use method calls for communication from the upper layer to the lower layer (only for queries, use Command for state changes). The interaction logic of IController is a special case and can only use Command.

The general rules are an ideal set of rules, but in actual projects, it is likely that some modifications need to be made to the above rules.

The modification method is very simple. For example, if I want IController to be able to send events, we only need to add an ICanSendEvent interface to the IController interface, as shown below:

    #region Controller
 public interface IController : IBelongToArchitecture, ICanSendCommand, ICanGetSystem, ICanGetModel,
        ICanRegisterEvent, ICanSendQuery,
        ICanSendEvent // +
    {
    }

    #endregion

In this way, we can send events in the Controller object through this.SendEvent.

If you intend to learn or study the QFramework architecture, I recommend that you first practice projects according to the default architecture specifications of QFramework.

If you intend to use QFramework to do projects immediately, you can gradually introduce QFramework concepts based on your original development habits, such as using BindableProperty and Architecture to solve the problem of Model and data updates at the beginning.

Then gradually use Command to solve the problem of bloated interaction logic, and so on, until you can fully master all concepts and finally modify and customize the QFramework.cs source code.

Summary

  1. 4-layer architecture, from top to bottom: Controller, System, Model, Utility

  2. The upper layer can obtain the lower layer, but the lower layer cannot obtain the upper layer.

  3. The upper layer notifies the lower layer using method calls.

  4. The lower layer notifies the upper layer using events.

  5. Through interfaces, you can have flexible control over the capabilities of each level. For example, adding an implementation interface to Controller can increase the ability to send events.

Previous Next

© Copyright 2023 - 2023, QFramework. Revision 0387bad1.

Built with Sphinx using a theme provided by Read the Docs.