首页 \ 问答 \ 我该如何自动安排?(How can I make proper arrangement automatically?)

我该如何自动安排?(How can I make proper arrangement automatically?)

之前

我的代码;

        label1.Text = "myLine1\nmyLine2\nmyLine3";
        label2.Text = "myLine4";

你可以看到,我输了第3行。

我想这样做。

(我试了好几次试验和错误。我已经将“Label2”移到了较低的位置。我想找出Label1和Label2之间的一些自动排列)。

在此处输入图像描述


Before

My codes;

        label1.Text = "myLine1\nmyLine2\nmyLine3";
        label2.Text = "myLine4";

As you can see it, I lost line 3.

I'd like to make like this.

(I made it with several times of trial and error. I've moved "Label2" lower position. I'd like to find out some automatic arrangement between Label1 and Label2).

enter image description here


原文:https://stackoverflow.com/questions/38372597
更新时间:2023-06-18 15:06

最满意答案

是的,这是针对OOP的。 你的关系是has-a ,而不是is-a

你应该使用组合而不是继承。

class Country{
      Military m;  //Country has-a military
      int a,b;
public:
      Country();
      void doSomething();
}

class Military{
      Technology t; //Military has-a technology
public:
      Military();
      void doAnother();
      void doAnother2();
}

class Technology{
public:
      Technology();
      void doAnother3();
}

Yes, it's against OOP. You relationships are has-a, not is-a.

You should use composition instead of inheritance for this.

class Country{
      Military m;  //Country has-a military
      int a,b;
public:
      Country();
      void doSomething();
}

class Military{
      Technology t; //Military has-a technology
public:
      Military();
      void doAnother();
      void doAnother2();
}

class Technology{
public:
      Technology();
      void doAnother3();
}

相关问答

更多
  • 也许: 加载资源 - > ResourceLoader 通过标识符 - > ResourceMapper映射资源 确保只加载一次资源 - > CachedResourceLoader /它在尚未加载时使用ResourceLoader 免费未使用的资源(使用smartpointers) - >? /不知道这个,但加载+卸载看起来像高度凝聚力的概念 在有关“免费未使用的资源”的评论中增加额外信息: 首先,让我们明确我们只有以上两个涉及:ResourceMapper和CachedResourceLoader。 由 ...
  • 我想有很多书籍和资料来源,你可以找到这些信息,我会给你指几本书,你可以在网络上找到纸质和PDF格式: “设计模式”由“四人帮”(Addison-Wesley,1994)。模式的权威指南。它在C ++和Smalltalk中都有例子,尽管它可能有点难以理解。 “设计模式为假人”,作者:Steve Holdner(Willey Publisinh Inc.,2006)这本书更简单,更容易理解/遵循。 从计算机科学的角度来看,它可能有点“弱”或非正式,但我确信你可以从本书中通过学习一种给定的设计模式开始,并通过Go ...
  • 这可能会更先进,然后才能开始正确的轨道。 如果你不了解这里的所有内容,不要太担心。 这是Scott Hanselman与Bob叔叔交谈描述SOLID http://www.hanselminutes.com/default.aspx?showID=163 您还可以查看Object Mentor http://www.objectmentor.com/videos/video_index.html上可用的资源 玩的开心! This may be more advanced then you are after ...
  • 更好的方法是: interface Algorithm { void executeAlgorithm(); } 并有类,实现算法接口,而不是功能。 Algorithm1,Algorithm2,Algorithm3等。 有桌子: Algorithm[,] algorithmTable = { { new Algorithm1(), new Algorithm2() }, { new Algorithm3(), new Algori ...
  • 这完全没有意义吗? 如果你的三个对象有你所说的type ,那么它就没用了,因为你只能在你的超类中编写一个setter和getter而不是在每个子类中实现它。 事实上,如果每个子类都有一个公共属性,那么超类就没用了。 然后对于颜色,您可以使用Enum而不是静态变量: public enum Colours{ YELLOW, RED, WHITE, NORMAL } 例如,使用Colours.RED访问它们。 Is this totally pointless? if your three objec ...
  • 如果您对每个供应商有不同的行为,则选项1将更合适,在这种情况下,选择2与其更简单似乎是更好的选择。 当我不知道如何解决问题时,我通常会这样做: 列出我的要求:获得给定供应商组件的最佳价格。 创建候选对象列表:供应商,项目,零售商等 绘制或布局类与我认为我有道理的关系 当我迷路时,我开始为要求编写主要类,在这种情况下,它将是零售商和GetBestRetailer()方法。 对于上述任何情况,无论你是否错误都无所谓,是一种头脑风暴,可以更好地理解你必须达到的目标以及找到的选择。 每当你遇到困难的事情时,我都会通 ...
  • 如果每个方法都只是一个直接调用数据源的静态调用,那么“Posts”类实际上就是一个Factory。 您当然可以将“Posts”中的静态方法放入“Post”类(这是CSLA的工作方式),但它们仍然是工厂方法。 我会说“Posts”类的更现代和准确的名称将是“PostFactory”(假设它只有静态方法)。 我想我不会说这是一种“程序性”方法 - 它只是一个误导性的名称,你会假设在现代OO世界中“帖子”对象是有状态的并提供操纵和管理一组的方法“发布”对象。 If every method is just a s ...
  • 是的,这是针对OOP的。 你的关系是has-a ,而不是is-a 。 你应该使用组合而不是继承。 class Country{ Military m; //Country has-a military int a,b; public: Country(); void doSomething(); } class Military{ Technology t; //Military has-a technology public: M ...
  • 在gof书中,客户端是使用模式中的类的代码或类。 例如,从动机下的抽象工厂模式: 考虑支持多种外观标准的用户界面工具包,例如Motif和Presentation Manager。 不同的外观定义了用户界面“小部件”(如滚动条,窗口和按钮)的不同外观和行为。 为了在外观标准之间移植,应用程序不应对其小部件进行硬编码以获得特定的外观。 在整个应用程序中实例化特定于外观的小部件类使得以后很难改变外观。 我们可以通过定义一个抽象的WidgetFactory类来解决这个问题,该类声明了一个用于创建每种基本类型的小部件 ...
  • 您是否被要求进行高级模型(模块)设计或低级模型设计? 处理高级模型设计的大问题或域是一个好主意,因为对于低级模型设计通常需要较小的问题或域。 通常,要求/问题来自提问者(用户/访谈员),因此我们不再需要定义业务要求。 但我们仍然需要设计系统。 高级模型 我不太熟悉“Apple Genius推荐系统”所以我将使用不同的问题类比,这是常见Point Of Sales问题。 对于高级模型,您将定义整个系统。 通常约为: 排序 下订单 首付 货物交付 返回 这就是所有高级模型/模块。 如果我被问到如何实现该模型,我 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)