什么是反模式? [英] What is an anti-pattern?

查看:122
本文介绍了什么是反模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究模式和反模式.我对模式有一个清晰的认识,但是我没有反模式.网络和维基百科的定义让我非常困惑.

I am studying patterns and anti-patterns. I have a clear idea about patterns, but I don't get anti-patterns. Definitions from the web and Wikipedia confuse me a lot.

有人可以简单地向我解释什么是反模式吗?目的是什么?他们在做什么?是好事还是坏事?

Can anybody explain to me in simple words what an anti-pattern is? What is the purpose? What do they do? Is it a bad thing or good thing?

推荐答案

反模式是某些软件开发模式,被认为是不良的编程习惯.

Anti-patterns are certain patterns in software development that are considered bad programming practices.

设计模式相反,这是解决常见问题的常用方法形式化,通常被认为是良好的开发实践,反模式则相反,是不理想的.

As opposed to design patterns which are common approaches to common problems which have been formalized and are generally considered a good development practice, anti-patterns are the opposite and are undesirable.

例如,在面向对象的编程中,想法是将软件分成称为对象的小块.面向对象编程中的反模式是上帝对象,它执行许多功能,更好地分成不同的对象.

For example, in object-oriented programming, the idea is to separate the software into small pieces called objects. An anti-pattern in object-oriented programming is a God object which performs a lot of functions which would be better separated into different objects.

例如:

class GodObject {
    function PerformInitialization() {}
    function ReadFromFile() {}
    function WriteToFile() {}
    function DisplayToScreen() {}
    function PerformCalculation() {}
    function ValidateInput() {}
    // and so on... //
}

上面的示例有一个执行一切的对象.在面向对象的程序设计中,最好对不同的对象承担明确的责任,以使代码减少耦合,并最终提高可维护性:

The example above has an object that does everything. In object-oriented programming, it would be preferable to have well-defined responsibilities for different objects to keep the code less coupled and ultimately more maintainable:

class FileInputOutput {
    function ReadFromFile() {}
    function WriteToFile() {}
}

class UserInputOutput {
    function DisplayToScreen() {}
    function ValidateInput() {}
}

class Logic {
    function PerformInitialization() {}
    function PerformCalculation() {}
}

最重要的是,有很好的方法来开发具有常用模式的软件(设计模式),但是也存在开发和实现可能导致问题的软件的方法.被认为是不良软件开发实践的模式是反模式.

The bottom line is there are good ways to develop software with commonly used patterns (design patterns), but there are also ways software is developed and implemented which can lead to problems. Patterns that are considered bad software development practices are anti-patterns.

这篇关于什么是反模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆