工厂,服务和util类有什么(以及它们之间的区别)?软件项目中还有其他概念吗? [英] what are (and the difference between) factories, service and util classes? Are there any more concepts in a software project?

查看:51
本文介绍了工厂,服务和util类有什么(以及它们之间的区别)?软件项目中还有其他概念吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我了解一个典型软件项目的概念,但是我找不到与此有关的文章.

I am trying to get my head around the concepts of a typical software project, but I cannot find a decent article concerning this.

  • 什么是工厂?
  • 什么是服务?
  • 什么是util类?

  • What are factories?
  • What are services?
  • What are util classes?

它们之间的主要区别是什么?(例如,是什么使工厂无法提供服务等)

And what are the key differences between them? (ex, what makes a factory not a service, etc)

在软件项目中还有其他通用的概念吗?

And are there any more concepts in a software project that are common?

推荐答案

工厂是工厂的实现模式.这是一种创建对象的方式.

A factory is an implementation of The Factory Pattern. It's a way of creating objects.

服务是一个类,用于管理应用程序特定方面的问题.例如,如果您的应用程序对 People 对象进行了操作,则您可能具有某种 PersonService 来管理创建,编辑,删除等所有方面的问题.可以使用多种服务其他服务使用它来实现涉及您应用的多个领域的目标.例如,如果可以将 Person 添加到 Company ,则 PersonService CompanyService 可以一起工作必要的操作.通常会有另一个服务,例如 YourAppService 来协调这两个服务.执行此操作时,它称为外观模式.

A service is class that manages the concerns of a particular aspect of you application. For example, if you application operated on People objects, you might have some sort of PersonService to manage all the concerns of creating, editing, deleting, etc. Multiple services can be used by other services to accomplish goals that touch upon more than one domain area of your app. For example, if a Person can be added to a Company, the PersonService and CompanyService can work together to do the necessary operations. Usually there would be another service like YourAppService that coordinates those two services. When you do this it is called The Facade Pattern.

实用程序类是保存应用程序常规操作的类.例如,假设您需要在整个应用程序中使用一些正则表达式.您可能有一个 TextUtil 可以在Strings上运行,而在任何地方都可以.在Java项目中,我通常会创建一个 TestUtil 类,该类具有创建将在单元测试中使用的对象的方法(测试util本身也已通过测试).您可以将此用例视为工厂模式的实现.

A utility class is a class that holds operations that are general to your application. For example, say you need to use some regexes all over you app. You could have a TextUtil that operates on Strings and whatnot anywhere. In Java projects, I usually create a TestUtil class that has methods to create objects that I will use in unit tests (the test util is itself tested, too). You could consider this use case an implementation of the factory pattern.

有人认为,如果您在应用程序中使用了实用程序类,则这是不良设计的征兆.

Some people think that if you have utility classes that you use in your application, it is a symptom of bad design.

这篇关于工厂,服务和util类有什么(以及它们之间的区别)?软件项目中还有其他概念吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆