From e567d89f3eb0e64193b50b5be206a2cd6513110a Mon Sep 17 00:00:00 2001 From: DragonAura Date: Sat, 15 Oct 2022 23:16:51 +0800 Subject: [PATCH] feat: improve oop design MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 仿照THUAI5的API设计模式 --- CAPI/API/include/API.h | 59 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/CAPI/API/include/API.h b/CAPI/API/include/API.h index 9a2c9e1..3aabda2 100644 --- a/CAPI/API/include/API.h +++ b/CAPI/API/include/API.h @@ -128,9 +128,24 @@ protected: ILogic& logic; }; -class IHumanAPI : public IAPI +// 给Logic使用的IAPI接口,为了保证面向对象的设计模式 +class IAPIForLogic : public IAPI +{ + IAPIForLogic(ILogic& logic) : + IAPI(logic) + { + } + virtual void StartTimer() = 0; + virtual void EndTimer() = 0; +}; + +class IHumanAPI : public IAPIForLogic { public: + HumanAPI(ILogic& logic) : + IAPIForLogic(logic) + { + } virtual std::future StartFixMachine() = 0; virtual std::future EndFixMachine() = 0; virtual std::future GetFixStatus() = 0; @@ -141,9 +156,13 @@ public: [[nodiscard]] virtual std::shared_ptr GetSelfInfo() const = 0; }; -class IButcherAPI : public IAPI +class IButcherAPI : public IAPIForLogic { public: + ButcherAPI(Logic& logic) : + IAPIForLogic(logic) + { + } virtual std::future Attack(double angleInRadian) = 0; virtual std::future CarryHuman() = 0; virtual std::future ReleaseHuman() = 0; @@ -151,4 +170,40 @@ public: [[nodiscard]] virtual std::shared_ptr GetSelfInfo() const = 0; }; +class HumanAPI : public IHumanAPI +{ +public: + HumanAPI(Logic& logic) : + logic(logic) + { + } +}; + +class DebugHumanAPI : public IHumanAPI +{ +public: + DebugHumanAPI(Logic& logic) : + logic(logic) + { + } +}; + +class ButhcerAPI : public IButcherAPI +{ +public: + ButhcerAPI(Logic& logic) : + logic(logic) + { + } +}; + +class DebugButcherAPI : public IButcherAPI +{ +public: + DebugButcherAPI(Logic& logic) : + logic(logic) + { + } +}; + #endif \ No newline at end of file