从C到Z,哪个字母的单词在英语中最为常见?

2026-04-29 05:442阅读0评论SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计706个文字,预计阅读时间需要3分钟。

从C到Z,哪个字母的单词在英语中最为常见?

我尝试用图理解我的团队项目的继承,但似乎已经找到了我设置的某些限制。在写作过程中,我感到非常困扰,因为我尚未正确理解这些概念。

我试图理解我的团结项目的继承,但似乎已经找到了我的设置的限制.在写作的过程中,我感到很困惑,因为我仍在学习正确理解C#.

我有一组继承的类,它们基于两种不同的行为进行拆分,这样我就有了正确的引用.

然后我需要转换它们,以便我可以访问其中一个类中的方法.所以我的结构看起来像这样:

public class Behaviour : Position { public Handler reference; public Behaviour(int tx, int ty, Handler refer) : base (tx,ty){ reference = refer; } // overload public Behaviour(int tx, int ty) : base (tx,ty){} } public class Behaviour2 : Position { public SettingsHandler reference; public Behaviour2(int tx, int ty, SettingsHandler refer) : base (tx,ty) { reference = refer; } } public class SettingsHandler : Handler { public Settings level {get;set;} } public class Handler : MonoBehaviour{ virtual public void Enter(List<Node> n,Vector3 p){} virtual public void Exit(List<Node> n, Node curNode){} }

现在这个工作正常,直到我必须访问Handler.Enter或Handle.Exit.然后我迷失了如何正确设置类型.

所以我做了这样的事情:

//need to set temp : ??? temp; if(path[i] is Behaviour2){ temp = (Behaviour2)path[i]; } else { temp = (Behaviour)path[i]; } temp.reference.Enter();

临时类型应该设置为什么?

我想我可能误解了继承,因为我似乎得到了类型问题. C#是否有解决方案 – 我不能成为唯一一个陷入困境的人.但是我的大脑很难搞清楚.

您的问题源于这样一个事实,即基类的设计很糟糕,主要有以下几种:

>层次结构毫无意义.行为不是一种特殊的立场.首选组合继承.
>字段永远不应公开.使用属性,而不是字段.
>“是”检查是运行时类型检查;不要对多态行为进行运行时类型检查;使用虚拟方法.

让我们重新设计你的层次结构.

从C到Z,哪个字母的单词在英语中最为常见?

abstract class MyBehaviour { public Position Position { get; private set; } public Handler Handler { get; private set; } protected MyBehaviour(int x, int y, Handler handler) { this.Position = new Position(x, y); this.Handler = handler; } } class Behaviour1 : MyBehaviour { /* Whatever */ } class Behaviour2 : MyBehaviour { /* Whatever */ }

好的,现在我们想要执行处理程序……

MyBehaviour b = whatever; b.Handler.Enter();

完成.不需要临时变量.没有运行时类型检查.没有“如果”.行为提供了一种服务;你使用这项服务.您不必为了使用它提供的服务而询问行为类型;如果你这样做,在设计层面可能出现问题.

本文共计706个文字,预计阅读时间需要3分钟。

从C到Z,哪个字母的单词在英语中最为常见?

我尝试用图理解我的团队项目的继承,但似乎已经找到了我设置的某些限制。在写作过程中,我感到非常困扰,因为我尚未正确理解这些概念。

我试图理解我的团结项目的继承,但似乎已经找到了我的设置的限制.在写作的过程中,我感到很困惑,因为我仍在学习正确理解C#.

我有一组继承的类,它们基于两种不同的行为进行拆分,这样我就有了正确的引用.

然后我需要转换它们,以便我可以访问其中一个类中的方法.所以我的结构看起来像这样:

public class Behaviour : Position { public Handler reference; public Behaviour(int tx, int ty, Handler refer) : base (tx,ty){ reference = refer; } // overload public Behaviour(int tx, int ty) : base (tx,ty){} } public class Behaviour2 : Position { public SettingsHandler reference; public Behaviour2(int tx, int ty, SettingsHandler refer) : base (tx,ty) { reference = refer; } } public class SettingsHandler : Handler { public Settings level {get;set;} } public class Handler : MonoBehaviour{ virtual public void Enter(List<Node> n,Vector3 p){} virtual public void Exit(List<Node> n, Node curNode){} }

现在这个工作正常,直到我必须访问Handler.Enter或Handle.Exit.然后我迷失了如何正确设置类型.

所以我做了这样的事情:

//need to set temp : ??? temp; if(path[i] is Behaviour2){ temp = (Behaviour2)path[i]; } else { temp = (Behaviour)path[i]; } temp.reference.Enter();

临时类型应该设置为什么?

我想我可能误解了继承,因为我似乎得到了类型问题. C#是否有解决方案 – 我不能成为唯一一个陷入困境的人.但是我的大脑很难搞清楚.

您的问题源于这样一个事实,即基类的设计很糟糕,主要有以下几种:

>层次结构毫无意义.行为不是一种特殊的立场.首选组合继承.
>字段永远不应公开.使用属性,而不是字段.
>“是”检查是运行时类型检查;不要对多态行为进行运行时类型检查;使用虚拟方法.

让我们重新设计你的层次结构.

从C到Z,哪个字母的单词在英语中最为常见?

abstract class MyBehaviour { public Position Position { get; private set; } public Handler Handler { get; private set; } protected MyBehaviour(int x, int y, Handler handler) { this.Position = new Position(x, y); this.Handler = handler; } } class Behaviour1 : MyBehaviour { /* Whatever */ } class Behaviour2 : MyBehaviour { /* Whatever */ }

好的,现在我们想要执行处理程序……

MyBehaviour b = whatever; b.Handler.Enter();

完成.不需要临时变量.没有运行时类型检查.没有“如果”.行为提供了一种服务;你使用这项服务.您不必为了使用它提供的服务而询问行为类型;如果你这样做,在设计层面可能出现问题.