design-patterns

Implementing the Template Method pattern in C#

与世无争的帅哥 提交于 2021-02-04 15:31:09
问题 The template method pattern provides that the abstract base class has a not overridable method: this method implements the common algorithm and should not overridden in the subclasses. In Java the template method is declared final within the abstract base class, in C# the sealed keyword has a similar meaning, but a not overridden method can not be declared sealed . public abstract class Base { protected abstract AlgorithmStep1(); protected abstract AlgorithmStep2(); public sealed void

What is the pattern called where you override the values of an existing record but keep the values you didn't override?

梦想的初衷 提交于 2021-02-04 15:11:07
问题 I've seen this about six places: Maven 2 Configuration of pom.xml vs. your projects pom.xml the local project pom overrides the value of the global configuration one. vim Configuration Files: in the vim install directory, and in your user profile. Ruby on Rails (Sensible Defaults) Simphony 2 (a.k.a. the great grandson of MICROS 9700) all the records that come down from the enterprise (cloud) get overridden. To some extent in NTFS ACLs between parent and child directories when the child

APM, EAP and TPL on Socket Programming

我们两清 提交于 2021-02-04 10:57:42
问题 I found Difference between […]Async and Begin[…] .net asynchronous APIs question but this answer confused me a little bit. Talking about these patterns, Stephen said: Most *Async methods (with corresponding *Completed events) are using the Event-Based Asynchronous Pattern. The older (but still perfectly valid) Begin* and End* is a pattern called the Asynchronous Programming Model. The Socket class is an exception to this rule; its *Async methods do not have any corresponding events; it's

How does using the factory design pattern stop a class having to anticipate the class of objects it must create

你离开我真会死。 提交于 2021-02-04 08:15:06
问题 As I understand it the factory design pattern allows objects to be created through the use of a separate object that's sole aim is to create the first one. Different types of factory can be used to create different types of object. I understand that this hides the instantiation of the primary object however surely this is just replaced by the instantiation of the factory? A common advantage for this design pattern is that it stops a class having to anticipate the class of objects it must

Performance of Cloning (either by Cloneable Interface or Copy Constructor) a object vs Creating a new object in Prototype Pattern

与世无争的帅哥 提交于 2021-02-04 08:12:59
问题 Recently, while learning about Design Patterns, I learnt that the Prototype Pattern is very useful and performance efficient in scenarios where huge number of Object creation is needed. Prototype Pattern also minimizes the expense of too many object creations by making use of Cloneable interface or Copy Constructor in Prototype Pattern. But, I would like to know how does cloning or copying an object more efficient than creating a new object. A JVM level explanation would be great. Is this the

Association or Aggregation relationship for Facade design pattern?

纵然是瞬间 提交于 2021-02-04 07:26:05
问题 I'm studying the GoF design patterns, in particular the Facade pattern. I understand its use and implementation, but I have a doubt about its UML model. The solution proposed by my professor, summarized, is the following: public class Facade{ private ClassA c1; private ClassB c2; private ClassC c3; public Facade(){ this.c1 = new ClassA; this.c2 = new ClassB; this.c3 = new ClassC; } public void FacadeMethod(){ ... c1.operationA(); c2.operationB(); c3.operationC(); ... } } The UML model

Is it forbidden to use static methods in factory pattern?

♀尐吖头ヾ 提交于 2021-02-02 09:55:38
问题 I got told that using static methods when implementing the factory-method-pattern is wrong and should be avoided. Because I wasn't really familiar with the pattern I accepted that answer. After reading articles and getting deeper into it, I couldn't find any source which supports this statement. Can someone help me out with this situation. Should I avoid the static-keyword in factory-methods and if so, when are they useful? 回答1: The first thing to be 100% clear about is that there is no

Basic API in golang antipattern?

孤者浪人 提交于 2021-01-29 22:34:13
问题 Correct me if I'm wrong, but for my understanding of an API is that it is something that allows me to modify and request data through an interface, which is what I want to do in Go. For example I have a user interface: interface IUser { GetId() int GetName() string GetSignupDate() time GetPermissions() []IPermission Delete() } This already looks to me like active record and if I want to create a new user with a new id I would have to use new since Go doesn't support static functions as far as

Decorator for creating Scope with ScopedLifestyle.Flowing in Simple Injector

可紊 提交于 2021-01-29 22:27:11
问题 I need some help to understand what it's wrong in my configuration of the container. I based this implementation by using this example. Basically i need to implement some use case as database command based on that interface public interface IDatabaseCommand<TResult, TParam> { TResult Execute(TParam commandParam); } and i want to use a decorator that add the transaction safe functionality. Every command need to use a dedicated DbContext and the transaction has to be executed on that context To

It is possible to use child class to implement Separation of concerns using EF Core?

假如想象 提交于 2021-01-29 16:44:56
问题 My goal is async loading of related entities using DBContext. Let imagine two projects. The first named MyApp.Domain and contains domain entities. namespace MyApp.Domain { public class PlanPage { public Guid Id { get; set; } } } namespace MyApp.Domain { public class PlanPageDay { public Guid Id { get; set; } public Guid PlanPageId { get; set; } } } The second project named MyApp.Infrastructure.EntityFramework and contains configuration of projection entities to database. It also contains