Breaking

Tuesday, June 6, 2017

The most effective method to actualize the format technique configuration design in C#

The format technique configuration design enables you to characterize the skeleton of a calculation in a base class and concede the points of interest to subclasses


Configuration examples are demonstrated answers for repeating issues and complexities in programming advancement. Configuration designs fall into three classes: creational, auxiliary, and behavioral. Creational examples are utilized to make and oversee occasions of classes. Auxiliary examples are utilized to understand the connections among the elements. Behavioral plan designs manage protest coordinated effort and designation of duties. 

Take note of that the format strategy design has a place with the behavioral plan design class. In the segments that tail, we will analyze this plan design in detail. 

Why utilize the layout strategy design? 

The layout strategy configuration example is helpful when you have a skeleton of a calculation characterized in a base class and a little piece of the calculation may shift and is executed with variety in a subclass, i.e., the solid class. Basically, the format of the calculation is characterized in the base class and keeping in mind that specific strides of the calculation (the part that variesthose that differ from the base class) is are re-characterized in a solid class. 

The Gang of Four characterizes the layout technique design as takes after: 

Characterize the skeleton of a calculation in an operation, conceding a few stages to subclasses. Layout Method gives subclasses a chance to rethink certain means of a calculation without changing the calculation's structure. 

As it were, the format strategy gives you a chance to characterize a gathering of exchangeable, comparatively organized, multi-step calculations in your application. Take note of that each of these calculations holds fast to a similar grouping of steps yet has an alternate usage. The base class characterizes the structure of the calculation, while the determined classes characterize minor departure from the calculation without changing its structure. As the name of the example recommends, the base class fills in as a sort of format or placeholder. 

The format strategy design in real life 

How about we look at how this outline example can be actualized. The ordinary members in the format strategy example are a theoretical class and a solid class. Consider the class beneath, which contains two sorts of techniques. One characterizes each progression of a calculation, while the other is a format technique that controls the calculation and conjures the means. 

open dynamic class AlgorithmBase 


open void TemplateMethod() 


OperationA(); 

OperationB(); 

OperationC(); 


open dynamic bool OperationA(); 

open dynamic bool OperationB(); 

open dynamic bool OperationC(); 


As should be obvious, the dynamic class AlgorithmBase characterizes a TemplateMethod and three conceptual techniques that do the means in the calculation. 

Also, here's the solid class for your reference: 

open fixed class AlgorithmA : AlgorithmBase 


open supersede bool OperationA() 


Console.WriteLine("Inside OperationA() of AlgorithmA"); 

return genuine; 


open supersede bool OperationB() 


Console.WriteLine("Inside OperationB() of AlgorithmA"); 

return genuine; 


open supersede bool OperationC() 


Console.WriteLine("Inside OperationC() of AlgorithmA"); 

return genuine; 



The AlgorithmA class expands the AlgorithmBase class and actualizes each of the theoretical strategies. 

Thus, you could have another solid class that amplifies the AlgorithmBase class and actualizes each of the conceptual techniques its own specific manner. For example: 

open fixed class AlgorithmB : AlgorithmBase 


open abrogate bool OperationA() 


Console.WriteLine("Inside OperationA() of AlgorithmB"); 

return genuine; 


open abrogate bool OperationB() 


Console.WriteLine("Inside OperationB() of AlgorithmB"); 

return genuine; 


open abrogate bool OperationC() 


Console.WriteLine("Inside OperationC() of AlgorithmB"); 

return genuine; 



At long last, the accompanying code bit indicates how you can summon the layout strategies on occasions of the AlgorithmA and AlgorithmB classes. 

static void Main(string[] args) 


AlgorithmBase obj1 = new AlgorithmA(); 

obj1.TemplateMethod(); 

AlgorithmBase obj2 = new AlgorithmB(); 

obj2.TemplateMethod(); 

Console.Read(); 


The layout strategy configuration design enables you to execute a general calculation while leaving space for simple customization. You will probably think that its valuable over and over.



No comments:

Post a Comment