AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 16.02.2011, 11:11   #1  
Blog bot is offline
Blog bot
Участник
 
25,643 / 848 (80) +++++++
Регистрация: 28.10.2006
Greg On Dynamics Ax: Refactoring a long parameter list of boolean flags
Источник: http://feedproxy.google.com/~r/GregO...3/fT2Fe7WicdQ/
==============

If you have had the need to have a method accept many boolean arguments, you might design the method to accept a number of optional boolean parameters, such as:

public void print(boolean _proforma = false, boolean _hideFooter = false, boolean _hideHeader= false, boolean _archive = false)This is not the best design. For a start if you are happy to accept all the defaults but want to archive the printout you’ll need to call the method like this:

print(false, false, false, true);It also suffers from what refactoring practitioners call a “bad smell” – this one being a long parameter list, which makes it harder to read and understand, and gets worse over time as new arguments are added.

A refactoring to improve the design might be to introduce a (single) settings object to replace the parameters.
If you consider that to be overkill you may want to consider this alternative: replace the parameters with a single base Enum type:



Each enumeration element then has a value that maps to the two base binary. So the values for this base enum would be:
  • Proforma – 1
  • HideFooter – 2
  • HideHeader – 4
  • Archive – 8
This enables us to declare our print method like so:

public void print(DEV_PrintOptions _opts){if ((_opts & DEV_PrintOptions::Proforma) == DEV_PrintOptions::Proforma)// Do proforma stuffif ((_opts & DEV_PrintOptions::HideFooter) == DEV_PrintOptions::HideFooter)// Hide the footerif ((_opts & DEV_PrintOptions::HideHeader) == DEV_PrintOptions::HideHeader)// Hide the headerif ((_opts & DEV_PrintOptions::Archive) == DEV_PrintOptions::Archive)// Archive the printout}Which allows the method to be called in a more flexible way, specifying only the options you wish to override, for example:

// print out proforma and archive it (accepting the default to print the footer and header):print(Dev_PrintOptions::Proforma | Dev_PrintOptions::Archive);


Источник: http://feedproxy.google.com/~r/GregO...3/fT2Fe7WicdQ/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
Старый 16.02.2011, 11:51   #2  
S.Kuskov is offline
S.Kuskov
Участник
Лучший по профессии 2017
Лучший по профессии 2015
Лучший по профессии 2014
 
3,444 / 1781 (66) ++++++++
Регистрация: 28.04.2007
Адрес: Калуга
По мойму, в таких случаях лучше сделать параметры свойствами класса. В конструкторе инициализировать их значениями по умолчанию. Сделать на каждый параметр свой parmMethod, и перед вызовом метода print задать необходимые опции.
X++:
obj.parmProforma(true);
obj.parmHideHeader(true);
obj.print();
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
dynamics-ax: Official Details about Dynamics AX '6' released, including comments from Microsofts Kees Hertogh Blog bot DAX Blogs 0 11.01.2011 05:22
emeadaxsupport: List of fixes that improve performance of certain features in Dynamics AX 2009 Blog bot DAX Blogs 0 13.10.2009 19:06
gatesasbait: Dynamics AX 2009 SSRS and SSAS Integration Tips Blog bot DAX Blogs 3 09.07.2009 13:07
Microsoft Dynamics CRM Team Blog: List Web Part for Microsoft Dynamics CRM 4.0 Deployment Scenarios Blog bot Dynamics CRM: Blogs 0 30.01.2009 22:05
axStart: Microsoft Dynamics AX 2009 Hot Topics Web Seminar Series Blog bot DAX Blogs 0 06.08.2008 12:05

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 03:54.