java中的DRY原则 [英] DRY principle in java

查看:398
本文介绍了java中的DRY原则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读DRY原则。虽然看起来很容易,但我很难理解我们在任何Project Web it Application或Swing中如何实现它?
可能只有少数例子可以帮助我发展我的思维过程。
我试图在Google上搜索但找不到合适的东西。

I have been reading DRY principle.Though it seems so easy but I am having difficulty in understanding how we actually achieve it in any Project be it Web Application or Swing? May be few examples will give me lead and help me in developing my thought process. I have tried to search on Google but could not find any thing suitable.

推荐答案

DRY不需要任何例子。如果您正在将代码块从一种方法,函数或代码块复制并粘贴到另一种方法,那么您就违反了DRY。

DRY is nothing that requires examples. If you are copying and pasting blocks of code from one method, function or block of code to another, then you are in violation of DRY.

很简单,DRY告诉您将该代码移动到可重用的单元中:或者转换为函数或方法或宏,或者与编程语言相关的其他机制。如果您的代码库中有明显具有非常相似代码的地方(即使有微小的变化),那么您应该考虑重构该代码以使其变干。

Very simply, DRY tells you to move that code into a reusable unit: either into a function or method or macro, or other mechanism relevant to your programming language. If you have places in your codebase where you clearly have very similar code (even with minor variations) then you should be looking to refactor that code to make it DRY.

不要重复自己! ==不要重复写相同的代码

"Don't repeat yourself!" == "Don't write the same code repeatedly"

这篇关于java中的DRY原则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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