我们的后端遵循三层架构:
- Presentation: This layer contains the endpoints.
- Services: Here, we implement the business logic.
- Data: This layer includes the Data Access Objects (DAOs)
responsible for communicating with the database.
除了这个结构之外,我们还有一些文件夹:
- Models: This folder contains interfaces that represent our business objects.
- Utils: Here, we manage logic that is not directly related to
the business domain, such as handling dates, strings, and numbers.
现在,关于在此架构中实现策略模式的类的放置:
考虑到策略的实现涉及可能需要访问不同服务的业务逻辑,避免循环依赖可能具有挑战性
我总是在纠结把这些设计模式对象放在哪里(这与我的工厂、我的建造者、状态类似......)
考虑到战略的实施涉及 可能需要访问不同服务的业务逻辑,它可以 避免循环依赖具有挑战性
可以创建一个称为
Common
的层,并放置不同服务可能需要的所有类。有了这样的库,就可以避免循环依赖。
我总是纠结把这些设计模式对象放在哪里
您不必创建一个单独的库来放置设计模式。设计模式是解决某些设计任务的方法。例如:您有很多课程,并且想要应用一些
Factory
模式。不需要为 Factory
模式创建单独的库,您所做的只是创建作为该模式实现的类。