Unity架構分層

將專案分為四層

  1. 表現層:為ViewController 或是 MonoBehaviour腳本,在這一層主要與顯示相關
  2. 表現邏輯:指的是當Model資料變更之後,View顯示更新之後的資料,即Model -> View;可以使用呼叫方法,委託,事件三種方式完成。
  3. 交互邏輯:為接收使用者輸入之後改變Model資料,即View -> Model;可以使用Command pattern減輕Controller的負擔,注意:command是沒有狀態的,他類似一個方法,呼叫之後就不用了
  4. Model層:管理資料,提供資料的增刪改查
  5. Utility層:工具層,提供一些共用的工具,如資料儲存、網路連接、藍芽、序列化與反序列化等
  6. System層:系統層,提供API且有狀態的物件,例如藍芽服務,計時器服務,網路服務等

這四層的交互

  • 表現層改變Model層System層的狀態會使用Command,
  • System層Model層通知表現層使用事件或是委託,
  • 表現層查詢狀態時可以直接獲取System層Model層
  • 一般,表現層不會訪問到Utility層Utility層也不會通知表現層

C# 明確方式實作介面

明確方式實作介面(Explicit Interface Implementation)

如果一個class去實作兩個有相同方法的interface,會發生什麼事?
程式如下,分別有兩個interface IControlIAction都含有Move()方法,其中ExampleClass去實作這兩個Interface。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public interface IControl
{
void Move();
}
public interface IAction
{
void Move();
}
public class ExampleClass : IControl, IAction
{
// Both IAction.Move and IControl.Move call this method.
public void Move()
{
Console.WriteLine("Move method in ExampleClass");
}
}

執行

1
2
3
4
5
6
7
8
9
10
11
12
13
ExampleClass example = new ExampleClass();
IControl control = example;
IAction action = example;

// The following lines all call the same method.
example.Move();
control.Move();
action.Move();

// Output:
// Move method in ExampleClass
// Move method in ExampleClass
// Move method in ExampleClass

結果是都會呼叫同一個實作。


但是你可能希望個自Interface執行不同的實作,這時就可以使用Explicit Interface Implementation如下:

1
2
3
4
5
6
7
8
9
10
11
public class ExampleClass2 : IControl, IAction
{
void IControl.Move()
{
System.Console.WriteLine("IControl.Move");
}
void IAction.Move()
{
System.Console.WriteLine("IAction.Move");
}
}

執行

1
2
3
4
5
6
7
8
9
10
11
12
ExampleClass2 example2 = new ExampleClass2();
IControl control = example2;
IAction action = example2;

// The following lines all call the same method.
//example2.Move(); // Compiler error.
control.Move(); // Calls IControl.Move on ExampleClass2.
action.Move(); // Calls IAction.Move on ExampleClass2.

// Output:
// IControl.Move
// ISurface.Move

此時,不可以直接透過實作class的物件去直接呼叫,會出現編譯錯誤,必須要把該物件轉換為對應的interface,例如如果你想呼叫IControl的Move方法,那麼就把它轉換為IControl。

注意:Explicit Interface Implementation是沒有存取修飾詞的,因為它無法當做其定義類型的成員來存取。它只有在透過interface的執行個體呼叫時才能存取。

參考:https://learn.microsoft.com/zh-tw/dotnet/csharp/programming-guide/interfaces/explicit-interface-implementation

使用Hexo Admin

透過 hexo-admin 這套插件,就能透過GUI介面進行後台管理,如新增或編輯markdown文件,簡化了發布文章的流程。

  1. 安裝套件
  2. 使用終端機,並移動到Hexo專案位置下,之後執行以下指令
    1
    $ npm install --save hexo-admin 

安裝完成之後,啟動本地端Server就可以進入後台管理,如下

  1. bash $ hexo server -d
  2. 進入 http://localhost:4000/admin 可進入後台管理

注意: Hexo Admin已經不維護了

Hello World

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment