我应该使用哪种设计决策? [英] Which design decision should I use?

查看:134
本文介绍了我应该使用哪种设计决策?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计支票簿注册申请,用于我自己的个人项目和使用。我遇到了一些设计决策障碍,我想要一些输入。



首先,我最初想到创建一个完整的类来输入寄存器条目存储一切的数据库。但是,经过进一步反思,我认为应用程序的提取和存储功能可能应该在不同的类中(基于一个类应该只承担1个责任)。当我在纸上写下来时,我发现这两个类(提款和存款)具有相似的功能;在我看来应该是在同一个班级。



我将用C#开发这个应用程序。有什么其他选择或只是想我应该做什么?应该是在一个班级,还是应该处理多个班级?



谢谢

I am in the process of designing a checkbook register application, for my own personal project and use. I am running into some design decision stumbling blocks, which I would like some input for.

First, I initially thought of creating one whole class to input the register entries into the database which stores everything. However, upon further reflection I was thinking that maybe the withdrawal and deposit functionality of the application should be in different classes (On the basis that a class should only house 1 responsibility). When I wrote this out on paper, I found that the two classes (withdrawal and deposit) would have similar functionality; and in my mind should be in the same class.

I am going to develop this application in C#. What are other options or just thoughts on what I should do? Should it be in one class, or should it be dealt with multiple classes?

Thanks

推荐答案

就个人而言,我将拆分的方式不同:拥有一个Account类(具有存款和提款方法),但将应用程序的结构抽象为三层模型:演示,业务和数据访问。 Account类将在BL中,并与DL接口以从DB读取/写入。



没有充分理由说明帐户需要知道如何它被存储或显示 - 但由于它需要输入和输出机制(或者它不是一个帐户,它只是一个数字)它应该是一个单独的类。



想想现实世界的等价物:你不知道你的银行用你给它的钱做什么(DL),银行不关心你如何处理你的支票簿和收据,或者如果你写支票或使用Paypal进行提款(PL)。

您所拥有的是一种识别帐户的机制(帐号),一些授权程序(取决于银行)以及某些方式赚钱进出 - 并确保你有足够的资金来做这件事!
Personally, I would split is differently: have an Account class (which has Deposit and Withdrawal methods), but abstract the structure of the app into the Three Layer Model: Presentation, Business and Data Access. The Account class would be in the BL and would interface with the DL to read / write from the DB.

There is no good reason why an Account needs to know how it is stored, or displayed - but since it needs input and output mechanisms (or it's not an account, it's just a number) it should be a single class.

Think about the real world equivalent: you don't know what the heck your bank does with the money you give it (DL) and the bank doesn't care how you cope with your checkbook and receipts, or if you write a cheque or use Paypal to make a withdrawal (PL).
All you have is a mechanism for identifying the account (the account number), some authorisation procedures (depends on the bank) and some way(s) to get money in and out - and ensure that you have enough in place to do it!


这篇关于我应该使用哪种设计决策?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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