.NET food for the brains!

from Coding Blocks .NET , on 6/3/2016 , played: 1024 time(s)

In this episode we go back to the design pattern well that we've been away from for so long.  We cover the Command, Repository and Mediator design patterns.  It was hard for us to believe, but it's been almost a year since our last design patterns episode!!!  Come on in for fun, learning, and of course, our tips of the week. See the original show notes at: http://www.codingblocks.net/epsiode42 Leave us a review here: http://www.codingblocks.net/review Come join us Slackers! http://www.codingblocks.net/slack News Stitcher Reviews: Spectre013, Christoffer, Genius, HAM3rtag, joe_recursion_joe, Gearhead2k, Manriquey2k, Mike North, AndrewM, MildManneredCalvin, Freeleeks iTunes Reviews: Sid Savara, J. Mair, tonicorb, Nmkel999, Eschwartz20, mochadwi, Banjammin, wisco_cmo, NewZeroRiot, Nate_the_DBA, Pauloispaulo Joe’s chess game! Joe on Hello Tech Pros Software Engineering Radio #256 on Unit Testing !important is a CSS code smell. Do you name your IIFEs? You should. This is our 5th, Design Patterns Episode. Last one was in July 2015. 30: Adapter, Facade, and Memento 19: Iterators, Observers, and Chains 16: Strategy, Template, Null Object 11: Factories, Factory Methods, Builder, Prototype What type of development do you prefer? Front-End Back-End Full Stack Design Patterns - Command, Repository, and Mediator Command Pattern Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undo. It's not "method()" it's "new Object(), and later...object.invoke() Why? Nice, clean way of organizing your code. Especially if…. OO replacement for callbacks - meh Specify, queue, execute Undo Transactions/Logging Not mentioned: Macros Async Real World Applications GUI/Menus - copy/paste/undo/photoshop Video Games Age of Empires sent commands rather than the game state! It’s not if("B") { jump(); }, if(input[k]) { input[k].invoke() } Great for different contexts, like menus Parallel / Tasks Async/Await Queues / Multi-Step Wizards Queue up the commands, execute all at once Restaurants???? How it’s done: Client: Customer Receiver: Waiter I/Command: Order Invoker: Cook Great example on sourcemaking.com What about callbacks? Why not the observer pattern? Challenge for the listeners, program the command pattern - do it “by the book” Repository Pattern Why? Testable with isolated data layer Centrally managed access rules and logic Centralized caching strategy Allows you to separate business logic from data access logic Strongly typed entities Business entity associations Can apply a domain model to simplify business logic Decouple business entity from data storage technology - the repository doesn’t expose where it gets its data What? Sits between the data source and the business layer Maps data from the data source to an entity Persists changes from the entity back to the data source Can use the Unit of Work pattern for complex, multi-step operations Typically utilizes a Data Mapper Pattern, or an ORM such as Entity Framework in .NET Mediator Pattern What is it? The mediator pattern defines an object that encapsulates how a set of objects interact Source: Wikipedia Promotes loose coupling by keeping objects from referring to each other explicitly Promotes the Single Responsibility Principle by allowing communication to be offloaded to a class that handles just that. Similar to the Observer pattern Mediator pattern can be implemented during the observer pattern, The Observer pattern distributes communication by introducing “observer” and “subject” objects. Also similar to the Facade pattern in that it abstracts functionality of the classes. Examples Chat room

Download

Comments

blog comments powered by Disqus