Should you use a partial class across projects?

后端 未结 8 499
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-03 16:42

I have a class library with all my database logic. My DAL/BLL.

I have a few web projects which will use the same database and classes, so I thought it was a good

8条回答
  •  情话喂你
    2020-12-03 17:16

    I can't answer your question about the best way to organize your layers, but I can try to answer your question about how best to emulate partial classes.

    Here are a few thoughts:

    • The first thing that springs to mind is inheritance. It's not necessarily the best solution always, but you may not have a choice since you may need to be able to have your objects be able to be treated like the base class.
    • Composition is also a good choice (that is, wrapping the class in another class). This gives you a little bit nicer decoupling from your DAL, but can be tedious to implement.
    • If you really just need to add a method or two onto an existing class, you might also consider using an extension method, but these can quickly create spaghetti code if you use them too much.

提交回复
热议问题