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

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 12.06.2013, 19:12   #1  
Blog bot is offline
Blog bot
Участник
 
25,643 / 848 (80) +++++++
Регистрация: 28.10.2006
mfp: SysExtension Framework – to the rescue
Источник: http://blogs.msdn.com/b/mfp/archive/...he-rescue.aspx
==============
There is a coding pattern that has been proliferating the X++ code base for years. It is not an X++ best practices – nor is it object oriented; yet it is used quite heavily (unfortunately). Consider a simple class hierarchy with an abstract base class and 3 derived classes. A typical implementation of a factory would be a static method on the base class, like this: (Please ignore the type of the parameter – it could  be anything, I choose str for simplicity)



Now; the problems with this approach are many.

  • First of all the base class has references to the sub classes. Why is that a problem? Consider the base class is a framework class – is it a good idea for framework classes to have references to consumer classes of the framework? Of course not – we don’t like that coupling.
  • Secondarily; the 3 subclasses are all referenced by the same method. Any new sub class would require an update to the factory. This turns the method into a congestion point, and it creates a coupling between sub-classes.
The coupling between the 4 classes spells trouble. If you try to modularize an application written like this, you will quickly realize that the pattern above is bad. You cannot have references from lower-level models (aka. assemblies/modules) to higher-level models. Yet; having a single factory method is valuable and a good practice.

SysExtension Framework to the rescue.

Consider you decorate the subclasses with an attribute, like depicted here:



Then you can rewrite the factory method to this:



The extension framework returns an instance of the right subclass automatically. It uses the attribute to determine which subclass instance to create. Quite simple – extraordinary powerful!

Now notice:

  • Truly decoupled! New subclasses can be added without any changes to the base class.
  • Less code is required! In the example here the delta is not significant – but sometimes you have switch statements spanning hundreds of lines.
  • No change in the public API! The contract stays the same – this is an easy and low risk refactoring.
A few words of caution: There is a small performance impact on cold systems when using the SysExtension framework. In most cases you will not notice it; however – for performance critical paths, you should measure the impact of this change before going for it.

To learn more about the SysExtension framework see here.




==============
Источник: http://blogs.msdn.com/b/mfp/archive/...he-rescue.aspx
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
Теги
sysextension

 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
HK Framework DSPIC DAX: Программирование 21 11.12.2024 20:00
ax_gfm_framework_team: Ledger account combinations - Part 7 (Advanced topics) Blog bot DAX Blogs 0 16.02.2013 08:08
ax-erp: Reporting Framework in AX 2012 Blog bot DAX Blogs 0 19.07.2012 01:11
sumitsaxfactor: Reporting Framework in AX 2012 Blog bot DAX Blogs 0 14.06.2012 11:11
emeadaxsupport: Update to AX 2012 Framework Component Documentation: SysOperation Framework Blog bot DAX Blogs 0 09.06.2012 00:11
Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

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

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

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