UML类图中的接口,继承和Genrics [英] Interfaces, inheritance and Genrics in UML Class Diagram

查看:414
本文介绍了UML类图中的接口,继承和Genrics的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建模一个基于DAO模式的持久层,并且对使用Genrics和接口继承有一些疑问。

我会开始说基本的CRUD操作对于所有持久化实体都是相同的,所以我决定使用泛型提供一个基本的DAO接口。接下来会有其他接口继承基本合约以及与具体实现管理的实体相关的一些其他特定方法。

听起来很复杂,但它是其实很简单。在Java中,它会是这样的:

  public interface BasicDao< T> {

public T insert(T dataObject);

public T update(T dataObject);

public Boolean delete(T dataObject);

public T getUnique(BigInteger dataObjectId);

public List< T>得到所有();
}

public interface IModulesDao extends IBasicDao< IModule> {

public IModule getModuleByCode(String code);

$ / code>

正如你所看到的 IModulesDao 在基本合同中增加了一种方法,但具体实现仍然需要满足整个合同,这就是完成所有这些工作的想法。

现在我已阅读 UML类图和泛型关于如何在UML中对泛型进行建模以及这个例子。据说使用buond元素与子类型不同,我们不允许在合同中添加任何东西。所以据我了解,我将不得不创建中间类型来最终获得我的 IModulesDao 界面。

这听起来在概念上是正确的,但我不确定是否适合我的情况,因为 IModulesDao 只是一个扩展名或 IBasicDao 的子接口,并且没有任何意义可以继承中间子类型。恕我直言,它只会给图表增加一点噪音,没有任何好处。



这是我现在所拥有的,但不认为是完全正确的:





<您可以请我带着正确的方向来介绍如何为这种情况建模? 您可以使用 IModulesDao 而不添加新的函数,所以只需绑定泛型。所以它应该与 List< T> 类似,命名为 IBasicDao< T> 。然后使用这个绑定类,你可以创建一个实际上添加新方法的专门化,你可以调用这个专门的类 IModulesDao



但诚实地说,没有人需要比教皇更基督教了。 UML让你有相当的自由,如果它对读者来说是可以理解的,那么它很好。说了这样的话,你也可以很好地与你做到这一点。


I'm modeling a persistence layer based on DAO pattern and I have some doubts related to the use of Genrics and interfaces inheritance.

I'd start saying that basic CRUD operations are the same for all the persistable entities so I've decided to provide a basic DAO interface using Generics. Then there would be other interfaces that inherit the basic contract plus some other specific methods related to the entity that will be managed by the concrete implementation.

It may sound complicated but it's actually very simple. In Java it would be something like this:

public interface BasicDao<T> {

    public T insert(T dataObject);

    public T update(T dataObject);

    public Boolean delete(T dataObject);

    public T getUnique(BigInteger dataObjectId);

    public List<T> getAll();
}

public interface IModulesDao extends IBasicDao<IModule> {

    public IModule getModuleByCode(String code);
}

As you can see IModulesDao adds a single method to the basic contract but concrete implementations still have to meet the whole contract, which is the idea of doing all this.

Now I've read UML Class Diagram and Generics about how to model Generics in UML and also this example. It is stated that using a buond element is not the same than subtyping and we are not allowed to add anything to the contract. So as far as I understand it, I would have to create intermediate types to finally get my IModulesDao interface.

This sounds conceptually right but I'm not sure if fits in my case since IModulesDao is just an extension or sub-interface of IBasicDao and makes no sense to have an intermediate subtype to inherit from. IMHO it will add just noise to the diagram for no benefit.

This is what I have right now but don't think is entirely correct:

Could you please lead me in the right direction about how to model this case?

解决方案

You could use IModulesDao without adding the new function, so just binding the generic. So it should be named similar to your List<T> as IBasicDao<T>. Then using this bound class you can create a specialization that actually adds the new method and you can call that specialized class IModulesDao.

But honestly nobody needs to be more christian than the Pope. UML lets you quite some freedom and if its understandable to the reader then its fine. Having said that you could also live nicely with the way you did it.

这篇关于UML类图中的接口,继承和Genrics的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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