GFramework/docs/zh-CN/abstractions/core-abstractions.md
GeWuYou 317eddca9b docs(sidebar): 更新侧边栏导航结构并移除API参考页面
- 调整Core模块导航链接结构,从overview页面改为根路径
- 重构Core模块侧边栏,将原有的6个主要类别扩展为15个详细分类
- 精简Game模块侧边栏,保留场景管理和游戏设置两个主要功能
- 更新Godot集成模块侧边栏,新增协程、信号、存储等功能分类
- 修改源码生成器模块命名,将枚举扩展重命名为枚举生成器
- 新增抽象接口侧边栏,包含Core和Game抽象接口文档
- 调整教程模块顺序,新增入门教程和Godot集成教程分类
- 移除独立的API参考导航项,将其整合到相应模块中
- 修正生成器API文档链接路径错误问题
2026-02-11 12:52:14 +08:00

2.7 KiB
Raw Blame History

Core Abstractions

GFramework.Core.Abstractions 核心抽象接口定义

概述

GFramework.Core.Abstractions 包含了框架的所有核心接口定义,这些接口定义了组件之间的契约,实现了依赖倒置和面向接口编程。

核心接口

IArchitecture

应用程序架构接口:

public interface IArchitecture
{
    void Initialize();
    void Destroy();
    
    T GetModel<T>() where T : IModel;
    T GetSystem<T>() where T : ISystem;
    T GetUtility<T>() where T : IUtility;
    
    void RegisterModel(IModel model);
    void RegisterSystem(ISystem system);
    void RegisterUtility(IUtility utility);
}

IModel

数据模型接口:

public interface IModel
{
    void Init();
    void Dispose();
    
    IArchitecture Architecture { get; }
}

ISystem

业务逻辑系统接口:

public interface ISystem
{
    void Init();
    void Dispose();
    
    IArchitecture Architecture { get; }
}

IController

控制器接口:

public interface IController : IBelongToArchitecture
{
    void Init();
    void Dispose();
}

IUtility

工具类接口:

public interface IUtility
{
}

事件接口

IEvent

事件基接口:

public interface IEvent
{
}

IEventHandler

事件处理器接口:

public interface IEventHandler<TEvent> where TEvent : IEvent
{
    void Handle(TEvent event);
}

命令查询接口

ICommand

命令接口:

public interface ICommand
{
    void Execute();
}

IQuery

查询接口:

public interface IQuery<TResult>
{
    TResult Execute();
}

依赖注入接口

IIocContainer

IOC 容器接口:

public interface IIocContainer
{
    void Register<TInterface, TImplementation>() where TImplementation : TInterface;
    void Register<TInterface>(TInterface instance);
    TInterface Resolve<TInterface>();
    bool IsRegistered<TInterface>();
}

生命周期接口

ILifecycle

组件生命周期接口:

public interface ILifecycle
{
    void OnInit();
    void OnDestroy();
}

使用示例

通过接口实现依赖注入

public class MyService : IMyService
{
    private readonly IArchitecture _architecture;
    
    public MyService(IArchitecture architecture)
    {
        _architecture = architecture;
    }
}

自定义事件

public class PlayerDiedEvent : IEvent
{
    public int PlayerId { get; set; }
    public Vector2 Position { get; set; }
}

相关文档