Polymorphic Event Patterns for C/AL

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

18-1 Verifying Object Behavior and Collaboration Role playing – the act of simulating object behavior and collaboration by acting out an object’s behaviors.
Design Patterns. What are design patterns? A general reusable solution to a commonly occurring problem. A description or template for how to solve a problem.
Dept. of Computer Engineering, Amir-Kabir University 1 Design Patterns Dr. Noorhosseini Lecture 2.
Microsoft Dynamics Road To Repeatability Technical Deep Dive Server Extensibility in Microsoft Dynamics NAV Vjekoslav Babić, MVP.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
1. Context: Ambient Intelligence Ambient Intelligence (AmI) represents a vision of ubiquitous computing, sensing and actuating to unobtrusively enhance.
CERN – European Organization for Nuclear Research GS Department – Administrative Information Services Design Patterns in Groovy Nicolas Décrevel Advanced.
1 © Talend 2014 Service Locator Talend ESB Training 2014 Jan Bernhardt Zsolt Beothy-Elo
Vrije Universiteit amsterdamPostacademische Cursus Informatie Technologie Idioms and Patterns polymorphism -- inheritance and delegation idioms -- realizing.
Module 15: Implementing Messaging Patterns. Overview Lesson 1: Creating Adaptable Orchestration Ports Lesson 2: Receiving Multiple Related Messages.
Design Patterns Standardized Recurring model Fits in many location Opposite of customization Fundamental types of pattern Choose and use as desired and.
OOPs Object oriented programming. Based on ADT principles  Representation of type and operations in a single unit  Available for other units to create.
Todd Snyder Development Team Lead Infragistics Experience Design Group.
CSSE 374: 3½ Gang of Four Design Patterns These slides derived from Steve Chenoweth, Shawn Bohner, Curt Clifton, and others involved in delivering 374.
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
Claudio Lassala Software Developer EPS Software / CODE Magazine Session Code: DEV 201.
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
Object Oriented Software Engineering Chapter 16 and 17 review 2014/06/03.
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
Introduction to Design Patterns. Questions What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared.
Creational Patterns
What to know for the exam. Smalltalk will be used for questions, but there will not be questions about the grammar. Questions might ask – how particular.
Introducing Allors Applications, Tools & Platform.
Programmeerimine Delphi keskkonnas MTAT Programmeerimine Delphi keskkonnas MTAT Jelena Zaitseva
Proxy.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Gang of Four Patterns 23 total 15 useful How are they different from GRASP Patterns?
 Copyright 2005 Digital Enterprise Research Institute. All rights reserved. Enabling Components Management and Dynamic Execution Semantic.
OOPs Object oriented programming. Abstract data types  Representationof type and operations in a single unit  Available for other units to create variables.
Design Patterns. 1 Paradigm4 Concepts 9 Principles23 Patterns.
Design Patterns Introduction
Design Patterns SE464 Derek Rayside images from NetObjectives.com & Wikipedia.
BEHAVIORAL PATTERNS 13-Sep-2012 Presenters Sanjeeb Kumar Nanda & Shankar Gogada.
Chapter 8 Object Design Reuse and Patterns. More Patterns Abstract Factory: Provide manufacturer independence Builder: Hide a complex creation process.
Five Minute Design Patterns Doug Marttila Forest and the Trees May 30, 2009 Template Factory Singleton Iterator Adapter Façade Observer Command Strategy.
PROTOTYPE. Design Pattern Space Purpose ScopeCreationalStructuralBehavioral ClassFactory MethodAdapterInterpreter Template Method ObjectAbstract factory.
Polymorphism Lecture - 9.
7 April 2004CSci 210 Spring Design Patterns 2 CSci 210.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Design Patterns A brief introduction to what they are, why they are useful, and some examples of those that are commonly used.
Chapter 10 Design Patterns.
Presentation on GoF Design Patterns Submitted by WWW. ASSIGNMENTPOINT
Chapter 5:Design Patterns
MPCS – Advanced java Programming
Gang of Four’s Design Patterns for Microservices
Design Patterns Lecture part 2.
Introduction to Design Patterns
How to be a Good Developer
Behavioral Design Patterns
How to be a Good Developer
Design Patterns with C# (and Food!)
object oriented Principles of software design
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin.
How to be a Good Developer
Programming Models for Distributed Application
Advanced Programming Behnam Hatami Fall 2017.
GoF Design Patterns (Ch. 26)
Design Patterns Part 2: Factory, Builder, & Memento
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
Designing For Testability
Chapter 8, Design Patterns Introduction
Chapter 11 Class Inheritance
Chapter 8, DesignPatterns Facade
GoF Patterns Ch. 26.
Presentation transcript:

Polymorphic Event Patterns for C/AL Vjekoslav Babić Microsoft Dynamics NAV MVP

Polymorphism?

Polymorphic patterns Producer-Consumer Delegation Command Strategy Prototype Service Locator Factory Proxy Twin Provider Dependency Injection Builder Facade Bridge Visitor Transfer Object Composite Servant Plug-in Template Method Repository Mediator

Object-Oriented Polymorphism Subtyping polymorphism Interface polymorphism

Object-Oriented Polymorphism Subtyping Polymorphism Interface Polymorphism public class Vehicle { public virtual void Start() { } public virtual void Stop() { } } public class Car : Vehicle public void Honk() { } public class Bicycle : Vehicle public void Ring() { } public interface IVehicle { void Start(); void Stop(); } public class Car : IVehicle public void Start() { } public void Stop() { } public void Honk() { } public class Bicycle : IVehicle public void Ring() { }

Polymorphic design patterns (most common) Factory pattern Service locator pattern Strategy pattern Dependency injection Template method pattern Inversion of Control

Inversion of Control - Problem Dependency 2 What do I do now? Recompile? What about that one? Consumer Object (uses a dependency) Dependency 1 tightly-bound (compile time) This is obviously a bad practice!

Inversion of Control - Solution Dependency 1 Consumer Object (needs a dependency) Dependency Resolver (retrieves dependency) Dependency 2 loosely bound (run time) Problem solved! Dependency n...

Sad Truth About Polymorphism in C/AL ”There is no such thing as polymorphism in C/AL.” (some very astute C/AL developer)

Okay, but we do get close... Argument Table https://community.dynamics.com/nav/w/designpatterns/245.argument-table Facade Variant Facade https://community.dynamics.com/nav/w/designpatterns/246.variant-facade TempBlob Facade

Consider this...

A Closer Look: Argument Table

A Closer Look: Argument Table (Improved)

(determines actual codeunit) Facade Pattern Specific Codeunit A (called by facade) Caller Object (calls facade) Facade Codeunit (determines actual codeunit) Specific Codeunit B (called by facade)

A Closer Look: Facade

Variant Facade Pattern Specific Codeunit A (called by facade) Record Variant Caller Object (calls facade) Facade Codeunit (determines actual codeunit) Specific Codeunit B (called by facade)

A Closer Look: Variant Facade

TempBlob Facade Pattern Specific Codeunit A (called by facade) Caller Object (calls facade) Facade Codeunit (determines actual codeunit) Specific Codeunit B (called by facade) (serialize) (deserialize) TempBlob (carries context)

A Closer Look: TempBlob Facade Serialization Deserialization

And then we got EVENTS

How Exactly Do Events Help? ”Handled” pattern: https://nav-skills.com/2015/11/25/the-handled-pattern/

(publishes event) (manages flow) “Handled” Pattern Subscriber 1 (subscribes to event) Consumer Object (needs a dependency) “Handled” Facade (publishes event) (manages flow) Subscriber 2 (subscribes to event) invokes method Subscriber n... (subscribes to event)

“Handled” Pattern Flow Publisher Subscriber Find subscriber codeunit in charge of the event Call the event Make sure that event was handled Check if event is already handled Check if this codeunit is in charge of the event Execute logic Set “handled” parameter

A Closer Look: “Handled” Pattern

“Handled” in action

“Handled” Pitfalls Subscriber identification Multiple active subscribers Cross-call state preservation Infrastructure separation Infrastructure fragility

Let’s find a solution…

Manual subscriptions Event subscriptions can be: Manage subscription Static (automatic)  each call in a separate, fresh codeunit instance Manual  each call in the same instance that was bound to events Manage subscription BINDSUBSCRIPTION UNBINDSUBSCRIPTION

“Handled” Pitfalls after Manual Subscriptions Subscriber identification Multiple active subscribers Cross-call state preservation Infrastructure separation Infrastructure fragility

Another event pattern can help… Discovery Event https://community.dynamics.com/nav/w/designpatterns/271.discovery-event

Discovery Event Pattern Discovered modules Module 1 (subscribes to discovery event) Module 2 (subscribes to discovery event) Discoverer (publishes discovery event) Module n... (subscribes to discovery event)

“Handled” Pitfalls After Discovery Subscriber identification Multiple active subscribers Cross-call state preservation Infrastructure separation Infrastructure fragility

Solution: Module Binder Pattern Combines: Discovery Event Pattern “Handled” Pattern Achieves: Logic and infrastructure separation Infrastructure stability

A Closer Look: Module Binder Pattern Interface/Module Setup Module Module Manager Binder Codeunit (single instance) (static binding) Discovered interfaces Discovered modules subscriptions binds Consumer Object (calls interface) Interface / Facade (publishes business logic event) Logic Codeunit (manual binding) invokes

A Closer Look: Module Binder Pattern Infrastructure (static, does not change when new modules are provided) Module Binder Codeunit (single instance) (static binding) discovery event subscriptions binds discovery event Consumer Object (calls interface) Interface / Facade (publishes business logic event) Logic Codeunit (manual binding) invokes business logic event

(publishes business logic event) Interface Interface / Facade (publishes business logic event) Facade for the business logic Publishes business logic event

Module: Business Logic Codeunit (manual binding) Subscribes to interface event Executes specific business logic

Module: Binder Binds/unbinds business logic codeunit Binder Codeunit (single instance) (static binding) Binds/unbinds business logic codeunit Discovers module for a specific interface

Module Manager Handles discovery of interfaces and modules Handles binding/unbinding of module binders

Consumer Codeunit Invokes interface binding Calls interface Consumer Object (calls interface) Consumer Codeunit Invokes interface binding Calls interface Strictly speaking, this is not a part of the pattern, it is just an example

Demo Interface / Module Setup

Explicit subscriptions Challenges Call multiplication Explicit subscriptions Rogue subscribers Single subscribers

Solution Use Event Subscription virtual table to: Verify that there are only manual subscribers Verify that there are active subscribers before calling the method

Demo Module Binder Pattern in Action

To learn more...

Thank You! Please remember to fill out your session survey using the Directions 2016 Mobile App!