简单程序的面向对象,可扩展性和模块化

时间:2020-12-06 12:51:04

How efficiently we can apply object oriented-ness, extensability and modularity for simple program? If it is application I can identify Entities and relations between them. When it comes to simple program I am not able to do this.

我们如何有效地为简单程序应用面向对象,可扩展性和模块化?如果是应用程序,我可以识别它们之间的实体和关系。谈到简单的程序,我无法做到这一点。

Please help me in achieving object oriented-ness, extensability and modularity in the Berlin clock program in the link.

请帮助我在链接中的柏林时钟程序中实现面向对象,可扩展性和模块化。

http://technologyconversations.com/2014/02/25/java-8-tutorial-through-katas-berlin-clock-easy/

Thanks in Advance.

提前致谢。

1 个解决方案

#1


0  

Here's how I would tackle the problem

这是我如何解决这个问题

  1. object oriented-ness First of all find out all the entities involved in your problem. Then intepret them as classes. In this case for example the clock is based on different Lights and their inter communication to display actual time.
  2. 面向对象首先找出问题所涉及的所有实体。然后将它们作为类来解释。在这种情况下,例如时钟基于不同的灯和它们的相互通信以显示实际时间。

So I would consider Light as an abstract class and would also inherit different other lights (E.g. RedLight, YelloLight etc) from this abstract Light class and extend them.

所以我会认为Light是一个抽象类,并且还会从这个抽象的Light类继承不同的其他灯(例如RedLight,YelloLight等)并扩展它们。

  1. Extensability

Always use interfaces rather than directly accessing the classes. In this way you could replace or extend your classes

始终使用接口而不是直接访问类。通过这种方式,您可以替换或扩展您的类

  1. Modularity

Have your Model (Classes), Business Logic, UI Logic etc separated in different class libraries (or separate projects).

让您的模型(类),业务逻辑,UI逻辑等在不同的类库(或单独的项目)中分离。

Hope this simple explanation helped.

希望这个简单的解释有所助

#1


0  

Here's how I would tackle the problem

这是我如何解决这个问题

  1. object oriented-ness First of all find out all the entities involved in your problem. Then intepret them as classes. In this case for example the clock is based on different Lights and their inter communication to display actual time.
  2. 面向对象首先找出问题所涉及的所有实体。然后将它们作为类来解释。在这种情况下,例如时钟基于不同的灯和它们的相互通信以显示实际时间。

So I would consider Light as an abstract class and would also inherit different other lights (E.g. RedLight, YelloLight etc) from this abstract Light class and extend them.

所以我会认为Light是一个抽象类,并且还会从这个抽象的Light类继承不同的其他灯(例如RedLight,YelloLight等)并扩展它们。

  1. Extensability

Always use interfaces rather than directly accessing the classes. In this way you could replace or extend your classes

始终使用接口而不是直接访问类。通过这种方式,您可以替换或扩展您的类

  1. Modularity

Have your Model (Classes), Business Logic, UI Logic etc separated in different class libraries (or separate projects).

让您的模型(类),业务逻辑,UI逻辑等在不同的类库(或单独的项目)中分离。

Hope this simple explanation helped.

希望这个简单的解释有所助