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

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 11.12.2020, 21:12   #1  
Blog bot is offline
Blog bot
Участник
 
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
Navigate Into Success: Fun with Interfaces: Patterns
Источник: https://vjeko.com/2020/12/11/fun-wit...aces-patterns/
==============

Today I had my fifth live stream. The topic was interfaces, and this time I took a different angle at it: patterns. When I polled about live stream topics you’d like to hear about, most of you said “patterns”. So today’s stream covers several patterns and puts them in perspective of interfaces, or the opposite way around, however you like it.

The stream is available on my new http://vjeko.live/ page, and here it is if you hate clicking:

Inversion of Control

The first pattern I talked about was inversion of control. It’s not really a pattern, it’s a design principle. If anything, you could say it’s a group of patterns.

In tightly-coupled world, when an object A directly accesses object B, you could say that object A directly depends on object B. You can imagine, having objects directly depend on other objects is a bad idea. The problem in AL is that it’s all over the place. Nice thing is that interfaces and enums in AL make inversion of control seem almost natural. In fact, you don’t even have to think about it most of the times you use enums and interfaces.

I tried to explain this concept in simple terms in my video, so if you want to see how it maps to AL, check it out.

Dependency Injection

If you ever heard me speak about interfaces, you have also heard me mention dependency injection. Dependency injection is one of possible implementations of inversion of control principle. It’s a technique (or a pattern if you want) where the caller injects dependency into an object that it calls. My session today covers this in depth. I absolutely love this approach in C#, and with interfaces it’s now also easy to do it in AL.

Factory

Strictly speaking, there is no such thing as a factory pattern. There are two patterns that use the word “factory” in their name (they are factory method pattern, and abstract factory pattern). But strictly speaking, AL can’t achieve neither of them exactly as their UML description demands.

Still the principles of both can be summed under “factory” pattern, and in reality, there are varying implementations of general “factory” pattern principles that you can easily achieve in AL if you want. In my stream, I present a couple of those, and I give you templates that you can use as snippets or boilerplate for creating your own factories.

Discovery Factory Pattern

Now we are talking real AL. Officially, there is no such thing as “discovery factory pattern”, but it would be so cool if there actually was one. So I came up with it.

This pattern that I propose is extension of a generic “factory” pattern that applies the handled pattern (I called that one “gentlemen’s agreement pattern” once). It extends the factory pattern through a discovery-like event. If it discovers an implementation, it uses that one. If not, does the factory stuff in the usual way.

Repository with examples

Like (nearly) always with my demos, I publish code examples on my GitHub page. Check the “Fun with Interfaces – Episode 2” examples here:

https://github.com/vjekob/fwi2

Thanks for bearing with me through my technical difficulties, I’ll post another blog where I summarize my experience with live streaming, software, hardware, and configuration.

Have a great weekend, see you next week when I’ll talk about using interfaces for testability.

Read this post at its original location at https://vjeko.com/2020/12/11/fun-wit...aces-patterns/, or visit the original blog at https://vjeko.com. 5e33c5f6cb90c441bd1f23d5b9eeca34The post Fun with Interfaces: Patterns appeared first on Vjeko.com.




Источник: https://vjeko.com/2020/12/11/fun-wit...aces-patterns/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
Navigate Into Success: Fun with Interfaces Blog bot NAV: Blogs 0 27.11.2020 18:11
Navigate Into Success: Codeunit Interfaces – this time for real! Blog bot NAV: Blogs 0 27.11.2019 06:24
Navigate Into Success: Codeunit interfaces in AL Blog bot NAV: Blogs 0 03.02.2019 00:14
Navigate Into Success: OnAfter table event subscriber patterns and antipatterns Blog bot NAV: Blogs 0 17.05.2016 08:12
Navigate Into Success: I had a dream: decoupled NAV Blog bot Dynamics CRM: Blogs 0 19.06.2013 05:44

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

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

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 06:35.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.