面向对象的问题 - 混合控制器逻辑和业务逻辑 [英] oo question - mixing controller logic and business logic

查看:149
本文介绍了面向对象的问题 - 混合控制器逻辑和业务逻辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如果我在使用标准的条款,但是这是一个基本的面向对象的问题,我想解决的问题。

I'm not sure if I'm using "standard" terms, but this is a basic OO question I'm trying to resolve.

我在编写一个Windows窗体。我不希望在表单事件处理程序逻辑,所以我就打电话到自定义对象从那里。

I'm coding a windows form. I don't want logic in the form event handler, so I just make a call to a custom object from there.

目前的自定义对象,有两套逻辑。

At the custom object, there are two sets of logic.

  1. 在控制器的逻辑,它决定哪些需要得到完成和时间。
  2. 在这做什么,需要做实际的业务逻辑(例如执行一个数学运算,并返回结果的控制,等等)。

我的问题是,面向对象的架构允许在单个对象具有这两种?或者是建议分拆出来成为一个控制器对象和商业逻辑的对象?有没有一种设计模式,我应该参考这个?

My question is, does OO architecture allow for having both of these in a single object? Or is it recommended to split them out into a "controller" object and a "business logic" object? Is there a design pattern I should refer to for this?

有关目前,我已经开始下它们合并成一个对象的途径。这个对象有一个启动方法,它包含了控制器逻辑。此方法然后调用对象的根据需要的其他方法,并最终返回结果给对象的调用者。

For the time being, I've started down the route of combining them into one object. This object has a "start" method which contains the controller logic. This method then calls other methods of the object as needed, and ultimately returns results to the caller of the object.

推荐答案

在一般情况下,你应该有这两种不同的对象,但有一个限定词上。它可能是有意义的,如果你的项目足够小,你的对象模型是不是足够复杂,有组合成一个对象的功能;但是,如果你的功能是足够复杂,它几乎肯定会是更好地为您隔离控制器和业务对象。最起码,设计系统,放眼在以后的控制器和业务对象分开,如果你不完全,现在将它们分开。

In general, you should probably have these in two different objects, but there's a qualifier on that. It may make sense, if your project is small enough and your object model is not complex enough, to have the functionality composed into one object; however, if your functionality is complex enough, it's almost certainly going to be better for you to segregate the controller and the business objects. At the very least, design the system with an eye towards separating the controller and the business objects at a later point, if you don't completely separate them now.

这篇关于面向对象的问题 - 混合控制器逻辑和业务逻辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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