What's the difference between an Algorithm and a Design Pattern

后端 未结 12 807
轮回少年
轮回少年 2020-12-24 13:54

I was searching for \"Undo/Redo algorithms\" and found something marked as a duplicate, but the duplicate was a request for a \"Undo Design Pattern\". I\'d really like an al

相关标签:
12条回答
  • 2020-12-24 14:36

    An algorithm is like a recipe: a step-by-step process for performing some activity.

    A design pattern is like a blueprint: an structured collection of objects and associations and actions to accomplish some goal.

    0 讨论(0)
  • 2020-12-24 14:40

    Design patterns:

    • a solution to a common but generic problem.
    • general solution to general problem.
    • often have to be implemented each time it is used.

    Algorithm:

    • specific set of steps you can follow to answer particular problem.
    • implemented directly to solve specific problem.
    0 讨论(0)
  • 2020-12-24 14:41

    they are different: http://en.wikipedia.org/wiki/Design_pattern_(computer_science) vs http://en.wikipedia.org/wiki/Algorithm

    using the the command design pattern (http://en.wikipedia.org/wiki/Command_pattern), it is easy to implement undo/redo: http://www.cs.mcgill.ca/~hv/classes/CS400/01.hchen/doc/command/command.html

    related question: Design Pattern for Undo Engine

    0 讨论(0)
  • 2020-12-24 14:43

    A design pattern is a relatively vague description of how to solve a problem at an architectural level, with emphasis on flexibility and maintainability. An algorithm is a precise description of how to compute something specific, with an emphasis on correctness and efficiency.

    0 讨论(0)
  • 2020-12-24 14:45

    When I studied design pattern concept for the first time, I was also surprised why design patterns were introduced in the presence of algorithm. As my knowledge has been increasing with design patterns, I am reaching at this point that algorithm is entirely different approach to solve the problems and design pattern is different.

    Design pattern is basically a recurring solution of same problem for a software application in a particular context which is somehow not related with algo, because algorithm is the step by step instructions to solve the problem.

    0 讨论(0)
  • 2020-12-24 14:45

    A design pattern would determine how you design an algorithm (or may have nothing to do with algorithms, but let's say we're dealing with one that does), whereas an algorithm will be a set of solid, repeatable, implementable, steps to doing something. So no, I wouldn't call them interchangable.

    0 讨论(0)
提交回复
热议问题