【发布时间】:2010-12-07 12:04:39
【问题描述】:
我有一个名为Parameters 的对象,它在调用树中从一个方法到另一个方法在调用树中上下颠倒,跨越包边界。它有大约五十个状态变量。每种方法都可能使用一个或两个变量来控制其输出。
我认为这是一个坏主意,因为我无法轻易看到一个方法需要运行什么,甚至如果模块 Y 的参数组合与我当前的模块完全无关,甚至可能会发生什么。
有什么好的技术可以减少与这个上帝对象的耦合,或者理想地消除它?
public void ExporterExcelParFonds(ParametresExecution parametres)
{
ApplicationExcel appExcel = null;
LogTool.Instance.ExceptionSoulevee = false;
bool inclureReferences = parametres.inclureReferences;
bool inclureBornes = parametres.inclureBornes;
DateTime dateDebut = parametres.date;
DateTime dateFin = parametres.dateFin;
try
{
LogTool.Instance.AfficherMessage(Variables.msg_GenerationRapportPortefeuilleReference);
bool fichiersPreparesAvecSucces = PreparerFichiers(parametres, Sections.exportExcelParFonds);
if (!fichiersPreparesAvecSucces)
{
parametres.afficherRapportApresGeneration = false;
LogTool.Instance.ExceptionSoulevee = true;
}
else
{
调用者会这样做:
PortefeuillesReference pr = new PortefeuillesReference();
pr.ExporterExcelParFonds(parametres);
【问题讨论】:
-
“参数”是配置对象吗?
-
是的。用于让 UI 携带业务层可能需要的任何参数。
标签: oop refactoring god-object