gpt4 book ai didi

php - OOP 应用架构 : Which layer does a lazy loader sit in?

转载 作者:行者123 更新时间:2023-12-04 06:56:03 24 4
gpt4 key购买 nike

我正在计划为应用程序组件实现继承映射器模式
http://martinfowler.com/eaaCatalog/inheritanceMappers.html

它需要具有的一个功能是让域对象引用大量聚合项目(10,000 个其他域对象)

所以我需要某种延迟加载集合从聚合根域对象传递到其他域对象。

为了保持我的(php)模型脚本有条理,我将它们存储在两个文件夹中:

MyComponent\
controllers\
models\
domain\ <- domain objects, DDD repository, DDD factory
daccess\ <- PoEAA data mappers, SQL queries etc
views\

但现在我正在绞尽脑汁想知道我的懒加载集合在哪里。它似乎跨越了两层。在内部它是一种数据映射器,在外部它是一个域对象。

将它放在一个地方而不是另一个地方的任何建议/理由?

  • daccess = 数据访问
  • DDD = 领域驱动设计模式,Eric Evans - 书籍
  • PoEAA = 应用程序架构模式模式,Martin Fowler - 书籍
  • 最佳答案

    简单的答案是它可能位于您的数据访问层中。

    //Domain Object
    class Store {
    public function GetGiantListOfProducts() { }
    }

    //DataAccess Object
    class LazyLoadingStore extends Store {
    public function GetGiantListOfProducts() { // function override
    // data access code
    }
    }

    然后,您的 DAO 可能如下所示:
    class StoreProvider {
    public function GetStoreById($id) {
    //User expects a list of Store, but you actually return a list of LazyLoadingStore - nobody need know the difference
    }
    }

    更复杂的答案是——这很臭。你真的需要懒加载东西吗?重新检查聚合根可能是一个更好的主意。也许您根本不需要 $store.GetGiantListOfProducts() 方法,并且可以通过更改关系遍历来优雅地回避整个问题,其中每个 Product 都有一个 GetStore() 方法,您将获得如下产品列表:
    class ProductProvider {
    public function GetAllForStore($store) {
    // return list of products for the store
    }
    }

    另一方面,如果关系必须以您最初勾勒出来的方式存在,那么也许延迟加载实际上是一个对域有意义的概念?在这种情况下,它存在于域中,并且应该有一个比简单的 LazyLoader 更具体和更有意义的名称。

    说得通?

    关于php - OOP 应用架构 : Which layer does a lazy loader sit in?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2563473/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com