strategy-pattern

Look up service implementations dynamically

自作多情 提交于 2020-05-28 04:50:11
问题 Our Angular application has a service which can have different implementations, aka. “strategies”. For simplicity, let’s assume it’s an “event reporting” service. The event reporting service has a function for reporting information. Depending on a runtime preference, the reporting can either turned off, go to the console , or be sent to a REST API, or go somewhere else. Using pure TS, this would look like: interface IReporter { report (message: string): void; } class NoReporter implements

Look up service implementations dynamically

允我心安 提交于 2020-05-28 04:48:44
问题 Our Angular application has a service which can have different implementations, aka. “strategies”. For simplicity, let’s assume it’s an “event reporting” service. The event reporting service has a function for reporting information. Depending on a runtime preference, the reporting can either turned off, go to the console , or be sent to a REST API, or go somewhere else. Using pure TS, this would look like: interface IReporter { report (message: string): void; } class NoReporter implements

How to make this Strategy-Object pattern type safe

南楼画角 提交于 2020-03-04 19:42:47
问题 This is the long version of a question I asked earlier For the tl;dr version please see here: Link I am sorry for this wall of text, but please bear with me. I put a lot of effort into the question and I believe the problem at hand should interesting to many here. Background I am writing a UI Framework with a classic Scene Graph. I have an abstract Top-Level class called Component and many subclasses, some of which are concrete while others abstract as well. A concrete subclass might be

How to make this Strategy-Object pattern type safe

瘦欲@ 提交于 2020-03-04 19:41:06
问题 This is the long version of a question I asked earlier For the tl;dr version please see here: Link I am sorry for this wall of text, but please bear with me. I put a lot of effort into the question and I believe the problem at hand should interesting to many here. Background I am writing a UI Framework with a classic Scene Graph. I have an abstract Top-Level class called Component and many subclasses, some of which are concrete while others abstract as well. A concrete subclass might be

Fetching Strategy example in repository pattern with pure POCO Entity framework

北城以北 提交于 2020-01-13 06:52:29
问题 I'm trying to roll out a strategy pattern with entity framework and the repository pattern using a simple example such as User and Post in which a user has many posts. From this answer here, I have the following domain: public interface IUser { public Guid UserId { get; set; } public string UserName { get; set; } public IEnumerable<Post> Posts { get; set; } } Add interfaces to support the roles in which you will use the user. public interface IAddPostsToUser : IUser { public void AddPost(Post

What design/pattern to use for a Client application using multiple providers?

自作多情 提交于 2020-01-05 02:10:49
问题 This is a design related question. Lets say we have a public API called ClientAPI with a few web methods like CreateAccount, GetAccount. Depending on the customer, we use a number of different providers to fulfil these requests. So say we have ProviderA and ProviderB and ProviderC. ProviderA has a method signature/implementation of CreateAccount that needs (Firstname, Lastname) only and creates an account with ProviderA. ProviderB has a method signature/implementation of CreateAccount that

Unity Resolve Multiple Classes

时光总嘲笑我的痴心妄想 提交于 2020-01-01 04:56:27
问题 How do I get microsoft unity to 'construct' a list of classes for a given interface type. Very Simple example: List<IShippingCalculation> list = new List<IShippingCalculation>(); list.Add(new NewYorkShippingCalculation()); list.Add(new FloridaShippingCalculation()); list.Add(new AlaskShippingCalculation()); //Not What I want public void calcship(List<IShippingCalculation> list) { var info = new ShippingInfo(list); info.CalculateShippingAmount(State.Alaska) } //Somehow in unity, must i do this

How to create a strategy pattern in Objective-C?

一个人想着一个人 提交于 2019-12-31 09:03:47
问题 I need to develop a strategy pattern where i have a main class with other three classes where i need to refer to the objects of the other three classes using the main class object.To solve this is the strategy pattern will help me? If so please do give me the syntax in Objective-C? 回答1: You'll want to look at Objective-C's protocol mechanism. Here's a simple protocol with a single required method: @protocol Strategy <NSObject> @required - (void) execute; @end Then you declare a class that

Hangfire server unable to pick job in case of strategy design pattern

守給你的承諾、 提交于 2019-12-29 08:02:09
问题 I am having following application : 1) Mvc app : Hangfire client from where i will just enqueue jobs and host dashboard.This app will contains reference of my class library. 2) Console App : Hangfire server will live in this console application. 3) Class library : Shared library between hangfire server(Console app) and hangfire client(asp.net mvc) where my long running code will reside.Hangfire server will execute code of this library. I am having structure like below in Class library