基类VS实​​用工具类 [英] Base class vs Utility class

查看:126
本文介绍了基类VS实​​用工具类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两个也应是首选?

有一些方法其通过A类,B和C称为

There are some methods which are called by class A, B and C.

如果这些方法被封装在D类(A,b和C的基础)?

Should those methods be encapsulated in a class D (base of A, B and C) ?

如果这些方法封装在U类和其他类及牡丹它的对象来使用的方法是必需的。

Should those methods be encapsulated in a class U and other classes creats it's object to use the methods as required.

在应该采取什么样的决策依据?

On what basis decision should be taken?

感谢。

推荐答案

您应该做一个静态实用工具类。

You should make a static utility class.

仅使用继承,如果它是真正有意义—如果 A b ,和 C 实际上的一个 D

Only use inheritance if it's actually meaningful—if A, B, and C actually are a D.

这篇关于基类VS实​​用工具类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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