oo question - mixing controller logic and business logic

后端 未结 4 2162
我寻月下人不归
我寻月下人不归 2021-01-05 15:40

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

I\'m coding a windows form. I don\'t want logic in the form

相关标签:
4条回答
  • 2021-01-05 16:16

    The answer to you design question can is as the following scenario: how would you design your application if you also had to provide a web-client for it.

    Both your Windows Forms UI and you Web UI would be calling the same classes and methods. The only difference, then, would be how each populates the UI and communicates with the other layers.

    0 讨论(0)
  • 2021-01-05 16:25

    What you're doing is a form of "fat controller" architecture. These days software development is trending toward thin controllers.

    OO design is all about decoupling. If you internalize only one thing about OO programming, let it be that.

    Check out "Domain-Driven Design Quickly." This free e-book is a condensed introduction to the concepts covered in Eric Evans' important book "Domain-Driven Design."

    Getting educated in these concepts should help you to understand how to separate business logic from the controller, or service layer.

    0 讨论(0)
  • 2021-01-05 16:26

    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.

    0 讨论(0)
  • 2021-01-05 16:32

    No, I don't put business logic in controllers. I add an intermediate service layer that's injected into controllers. Let the service do the work. Controllers are for routing requests and marshaling responses.

    Putting the logic in a clean service layer is "service oriented", even if you aren't using web services or WSDL. It has the added benefit of still working if you decide to change controller/view technologies.

    0 讨论(0)
提交回复
热议问题