使用 IoC 和 CBD 制作基于组件的应用程序
我读过很多关于 IoC 和基于组件的设计的内容。然而,我有点不确定设计界面的最佳方式是什么。
我不确定它们应该有多粗或多细。以“货件”组件为例:
- 货件组件可以配置一些设置
- 用户可以向货件添加项目或从货件中删除项目
- 用户可以对货件执行一些功能来更改其状态,例如准备发货、授权、发货 但是,
该模块最简单的接口可能如下(伪代码):
public interface IShipment
{
AddItem(Item);
RemoveItem(Item);
ReadyForShipment();
Authorise();
Despatch();
Invoice();
}
我不确定这实际上是否是正确的接口。也许我们应该将它们分开:
public interface IShipmentContents
{
AddItem(Item);
RemoveItem(Item);
}
public interface IShipmentActions
{
ReadyForShipment();
Authorise();
Despatch();
Invoice();
}
或者我们可以将其发挥到极致,其中每个操作都成为一个接口,因此我们能够注入具体的实现 每个动作而不是一组动作。
有人可以给我指点一些阅读材料来帮助我理解 IoC 和 CBD 在现实世界应用程序中的应用吗?
I have read quite a bit about IoC and Component Based Design. However I am a bit unsure of what the best way it to design my interfaces.
I am not sure how coarse or fine-graded they should be. Consider the Shipment component as an example:
- The shipment component can be configured with some settings
- The user can add items to and remove items from the shipment
- The user can perform some functions on the shipment that changes it's state e.g. Ready For Shipment, Authorise, Despatch, Invoice, etc.
The simplest interface for this module could be as follows (pseudocode):
public interface IShipment
{
AddItem(Item);
RemoveItem(Item);
ReadyForShipment();
Authorise();
Despatch();
Invoice();
}
However, I am not sure whether this is in fact the proper interface. Maybe we should separate them:
public interface IShipmentContents
{
AddItem(Item);
RemoveItem(Item);
}
public interface IShipmentActions
{
ReadyForShipment();
Authorise();
Despatch();
Invoice();
}
Or we can take it to the extreme where each of the actions become an interface and thus us being able to inject concrete implementations of
each action instead of a group of them.
Can anone point me to some reading material to help me understand the application of IoC and CBD in a real world app?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论