Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this a design pattern?

All over our codebase we have this repeated pattern where there's an interface with one method. Is this a real design pattern? If so what is it and what would the benefits be?

Here are a few examples:

    public interface IRunnable
    {       
        void Run();     
    }

    public interface IAction
    {
        void Perform();
    }

    public interface ICommand
    {
        void Execute(ActionArgs _actionargs);
    }
like image 868
Nick Avatar asked Apr 14 '09 16:04

Nick


People also ask

Which is a design pattern?

In software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software design. A design pattern isn't a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations.

What is design pattern with example?

Design patterns provide a standard terminology and are specific to particular scenario. For example, a singleton design pattern signifies use of single object so all developers familiar with single design pattern will make use of single object and they can tell each other that program is following a singleton pattern.


1 Answers

I've seen this referenced as the Command pattern.

I first learned about it reading Uncle Bob's Agile Principles, Patterns, and Practices in C#.

I believe its elegance is its simplicity. I've used it when I wrote a file processing service. The service performed all of the administration of reading / deleting files. When a file needed to be processed, it's respective plugin was loaded. Each plugin implemented a Process method, and did whatever was needed to process that type of file. (Mainly, parse the contents and insert into a database.)

Everytime I had to process a new file type with a new layout, all I had to do was create a new Plugin that implemented Process.

This worked for me because I needed a simple solution. If you need to take in more than one parameter, this probably is not the pattern to use.

like image 138
Aaron Daniels Avatar answered Oct 05 '22 21:10

Aaron Daniels