我只是在读完这本书,里面有"HAS-A"和"IS-A"这两个词.谁知道具体是什么意思?尝试在书中搜索,但这本书长达600页.
从 Uncle Bob 的书 Clean Code(示例是在 Java 中编写的,所以这是我的第一个 Java 翻译),我一直在玩质数重构示例。
问题是:您将如何重构以下代码?
这里有 4 个版本:UglyVersion :-)、BobVersion、PeteVersion、PeteVersionClassMember。我这样做是为了好玩,希望你也喜欢:-)
class ProgramBad
{
static void Main()
{
int[] result = GeneratePrimes.generatePrimes(30);
foreach (var i in result)
Console.Write(i.ToString() + ", ");
}
}
/// <summary>
/// Given an array of integers starting at 2, cross out the multiples of 2. Fine the next
/// uncrossed integer, and cross out all of its multiples.
/// Repeat until you have passed the square root of the maximum value …Run Code Online (Sandbox Code Playgroud) 我有一个包含对象数组的对象.
things = new Object();
things.thing = new Array();
things.thing.push({place:"here",name:"stuff"});
things.thing.push({place:"there",name:"morestuff"});
things.thing.push({place:"there",name:"morestuff"});
Run Code Online (Sandbox Code Playgroud)
我想知道从数组中删除重复对象的最佳方法是什么.所以,例如,事情会变成......
{place:"here",name:"stuff"},
{place:"there",name:"morestuff"}
Run Code Online (Sandbox Code Playgroud) 我想在堆上分配一个结构,初始化它并从函数返回一个指向它的指针.我想知道在这种情况下我是否有办法初始化结构的const成员:
#include <stdlib.h>
typedef struct {
const int x;
const int y;
} ImmutablePoint;
ImmutablePoint * make_immutable_point(int x, int y)
{
ImmutablePoint *p = (ImmutablePoint *)malloc(sizeof(ImmutablePoint));
if (p == NULL) abort();
// How to initialize members x and y?
return p;
}
Run Code Online (Sandbox Code Playgroud)
我应该从中得出结论,在包含const成员的堆上分配和初始化结构是不可能的?
此测试失败:
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestMethod()]
public void dictEqualTest() {
IDictionary<string, int> dict = new Dictionary<string, int>();
IDictionary<string, int> dictClone = new Dictionary<string, int>();
for (int x = 0; x < 3; x++) {
dict[x.ToString()] = x;
dictClone[x.ToString()] = x;
}
Assert.AreEqual(dict, dictClone); // fails here
Assert.IsTrue(dict.Equals(dictClone)); // and here, if the first is commented out
Assert.AreSame(dict, dictClone); // also fails
}
Run Code Online (Sandbox Code Playgroud)
我误解了一些有关Dictionary工作的方法吗?
我正在寻找Java的等价物.equals(),而不是试图检查引用相等性.
我注意到,当我连续两次刷新页面或双击链接时,用户会自动注销.我正在使用cakephp 1.2和Auth组件.我对CakePHP没有很多经验,任何想法可能会导致什么?
假设我通过webview加载第三方URL.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webview = (WebView) findViewById(R.id.webview);
webview.setWebViewClient(new HelloWebViewClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebChromeClient(new MyWebChromeClient());
webview.loadUrl("http://ebay.com");
}
Run Code Online (Sandbox Code Playgroud)
我可以在这个WebView中注入一些东西来替换我自己的ebay徽标吗?
似乎我可以使用self或this引用混合实例,或者更确切地说是限制混合实例.例如,那些是等价的吗?
scala> trait A { self: List[_] => }
defined trait A
scala> trait B { this: List[_] => }
defined trait B
Run Code Online (Sandbox Code Playgroud)
这只是一个约定,还是使用不同的东西而不是this提供一些好处?
我确信这很简单,但我无法弄明白.我在这里和msdn上搜索过,但一直无法找到答案.我需要能够通过richtextbox.Selection.Select(TextPointer1,Textpointer2)设置richtextboxes选择.
嘿那些人,我正在学习processing.js,而且我遇到了一个数学问题,我似乎无法通过有限的几何和三角知识或维基百科的帮助解决这个问题.
我需要绘制一个矩形.要绘制这个矩形,我需要知道每个角的坐标点.我所知道的是盒子顶部和底部中点的x和y,以及所有四个边的长度.
无法保证盒子的方向.
有帮助吗?这看起来应该很容易,但它确实让我感到难过.
c# ×2
javascript ×2
.net ×1
android ×1
arrays ×1
c ×1
cakephp-1.2 ×1
dictionary ×1
duplicates ×1
equality ×1
geometry ×1
login ×1
logout ×1
math ×1
object ×1
oop ×1
refactoring ×1
richtextbox ×1
scala ×1
templates ×1
traits ×1
trigonometry ×1
webview ×1
wpf ×1