数据仓库类型的解决方案?数据仓库、解决方案、类型

2023-09-06 15:20:36 作者:魂梦归她处

我正在开发一个系统,删除其他系统的信息。例如,有一种顾客数据库和客户可以如果他们最近的顺序是六岁以上被删除。

I am developing a system that deletes information from other systems. For example, there is a Customers database and customers can be deleted if their most recent order is six years old or greater.

我能想到的两种方法如下:

I can think of two approaches to this:

为每个系统如中创建类客户(为客户数据库),顺序(订单数据库)等方面都称为函数删除各种类多态性,即客户端可以调用删除每个类,它将删除必要的记录。 复制所有做一个关于实体如决策所需要的信息订购到使用SSIS副本数据库,并产生应删除一切的一个大查询。这是一个数据仓库类型的方法。

我不能决定哪一个方案更好。

I cannot decide which option is better.

推荐答案

我会带走你的第一个方法的问题。我不知道,这是有道理的,所有的独立业务类的会以某种方式共享相同的接口,一个删除方法。删除一个客户所需要的参数可能不一样,以删除一个订单所需要的参数。这似乎很奇怪,迫使他们采用相同的接口。做这样的说法可能不必要地限制了你的code。在未来的灵活性。此外,它似乎很奇怪,对于删除客户的业务逻辑将涉及通过其他对象盲目循环,没有特定的顺序,并调用删除在所有这些方法。我倒是觉得你会希望有更多的控制权,他们被删除以及它是如何处理时的删除方法之一发生故障的顺序。

I would take issue with your first approach. I'm not sure that it makes sense that all of the separate business classes would somehow share the same interface for a Delete method. The parameters needed to delete a customer may not be the same as the parameters needed to delete an order. It seems odd to force them to share the same interface. Doing it that way may unnecessarily restrict the flexibility of your code in the future. Also, it seems odd that the business logic for deleting a customer would involve blindly looping through other objects, in no particular order, and calling a Delete method on all of them. I'd think you'd want to have more control over the order in which they get deleted and how it is handled when one of the delete methods fails.

我会建议它的第一个想法在一个较高的水平。你真的需要什么业务方法?根据您描述的情况,我可以看到两个业务方法:

I would suggest first thinking of it at a higher level. What business methods do you actually need? Based on the scenario you described, I can see two business methods:

获取在过去6年里所有的客户,没有订单列表 删除用户(以及其所有订单)

由于这两种这些方法都涉及到客户,这将是有意义的它们组合在一起成为一个单一的客户业务类,某种形式的。例如:

Since both of those methods are related to customers, it would make sense to group them together into a single customer business class, of some sort. For instance:

Public Interface ICustomerBusiness
    Function GetStaleCustomers(timeSinceLastOrder As TimeSpan) As IList(Of CustomerDto)
    Sub DeleteCustomer(customerId As Integer)
End Interface

一旦你已经封装业务逻辑这样的,现在无所谓了数据访问层是如何实现的。客户端将调用这些简单的业务层的方法和不必关心如何逻辑幕后工作。随着封装在自己的层中的业务逻辑,你就可以自由地重写它以不同的方式,而无需重写任何的客户端code。

Once you've encapsulated the business logic like that, now it doesn't matter how the data access layer is implemented. The client makes calls to those simple business layer methods and doesn't have to care how the logic works behind the scenes. With the business logic encapsulated in its own layer, you will be free to rewrite it in different ways without having to rewrite any of your client code.

那么,什么会是商业类里面的逻辑是什么样子?这可能是经由一台庞大的SQL命令做所有的工作数据访问方法,无论是单呼,或者它可以使许多调用单独做的每一步。这真的取决于你。显然前者能更有效,但后者将更加灵活。这完全取决于你的需求。下面是每个什么可能看起来像一个简单的例子:

So what would the logic inside that business class look like? It could be either a single call to a data access method that does all the work via one massive SQL command, or it could make many calls to do each step separately. That's really up to you. Obviously the former will be more efficient, but the latter will be more flexible. It will all depend on your needs. Here's a simple example of what each might look like:

Public Sub DeleteCustomer(id As Integer)
    _customerDataAccess.DeleteCustomerAndOrders(id)
End Sub

' or...

Public Sub DeleteCustomer(id As Integer)
    For Each i As OrderDto In _orderBusiness.GetOrdersByCustomer(id)
        _orderBusiness.DeleteOrder(i.Id)
    Next
    _customerDataAccess.DeleteCustomer(id)
End Sub

第二个选择是更灵活的多种原因。例如:

The second option would be more flexible for multiple reasons. For instance:

您将有更好的控制所发生的事情和时间。这将允许您提供详细的状态更新,如果需要的话,在此过程中。它也将让您在出现故障时提供详细的跟踪记录和更多的precise错误消息。 在业务逻辑删除的订单将被分解成一个单独的可重用的业务类。如果您需要删除刚才的顺序,从其他地方code的地方,你就可以通过共同的code这样做。