小编Dav*_*uth的帖子

Module.private_constant做什么?有没有办法只列出私有常量?

从Ruby 1.9.3开始,我们可以创建私有常量:

module M
  class C; end
  private_constant :C
end
Run Code Online (Sandbox Code Playgroud)

关于它的作用是否有良好的文档?有没有办法获得类似于调用的私有常量的名称constants

ruby private constants ruby-1.9.3

8
推荐指数
2
解决办法
3320
查看次数

Recyclerview,我无法通过getChildAt(位置)获取项目视图.空对象引用

我在导航抽屉里面使用了recyclerView,我正在使用这个库Twoway-view来获得点击和选择支持.

它工作得很好,我可以在每个位置的OnClick方法中更改文本和图标的颜色而没有问题:

itemClickSupport.setOnItemClickListener(new ItemClickSupport.OnItemClickListener() {
        @Override
        public void onItemClick(RecyclerView parent, View view, int position, long id) {
            TypedValue typedValue = new TypedValue();
            MainActivity.this.getTheme().resolveAttribute(R.attr.colorAccent, typedValue, true);
            final int color = typedValue.data;

            //TODO Icon and text colors

            for (int i = 0; i < drawerTitles.length; i++){
                if (i == position){
                    ImageView imageViewDrawerIcon = (ImageView) recyclerViewDrawer.getChildAt(i).findViewById(R.id.imageViewDrawerIcon);
                    TextView textViewDrawerTitle = (TextView) recyclerViewDrawer.getChildAt(i).findViewById(R.id.textViewDrawerItemTitle);
                    imageViewDrawerIcon.setColorFilter(color);
                    if(Build.VERSION.SDK_INT > 15){
                        imageViewDrawerIcon.setImageAlpha(255);
                    }else{
                        imageViewDrawerIcon.setAlpha(255);
                    }
                    textViewDrawerTitle.setTextColor(color);
                    RelativeLayout relativeLayoutDrawerItem = (RelativeLayout) recyclerViewDrawer.getChildAt(i).findViewById(R.id.relativeLayoutDrawerItem);
                    relativeLayoutDrawerItem.setFocusableInTouchMode(true);
                }else{
                    ImageView imageViewDrawerIcon = (ImageView) …
Run Code Online (Sandbox Code Playgroud)

android get-childitem android-recyclerview

8
推荐指数
4
解决办法
2万
查看次数

取决于抽象是否有任何明显的缺点?

在使用稳定抽象原理(SAP)阅读维基之后,我想知道是否有人知道取决于抽象而不是混凝土的任何缺点(我认为,这超过了优势).

SAP声明包越稳定,它应该越抽象.这意味着如果包装不太稳定(更有可能改变),那么它应该更具体.我真的不明白为什么会出现这种情况.当然,在所有情况下,无论稳定性如何,我们都应该依赖于抽象并隐藏具体实现?

architecture oop design-patterns package-design

8
推荐指数
1
解决办法
156
查看次数

接口实现中多个if语句的最佳设计模式

我的IComposerc#项目中有一个界面:

public interface IComposer
{
    string GenerateSnippet(CodeTree tree);
}
Run Code Online (Sandbox Code Playgroud)

CodeTree是一个基类,包含一个List<CodeTree>继承自的类CodeTree.例如:

public class VariablesDecleration : CodeTree
{
     //Impl
}

public class LoopsDecleration : CodeTree
{
     //Impl
}
Run Code Online (Sandbox Code Playgroud)

我可以有几个实现的类,IComposer每个我都有GenerateSnippet循环List<CodeTree>,基本上做:

foreach (CodeTree code in tree.Codes)
{
    if (code.GetType() == typeof(VariablesDecleration))
    {
        VariablesDecleration codeVariablesDecleration = (VariablesDecleration) code;
        // do class related stuff that has to do with VariablesDecleration
    }
    else if (code.GetType() == typeof(LoopsDecleration))
    {
        LoopsDecleration codeLoopsDecleration = (LoopsDecleration) code;
        // …
Run Code Online (Sandbox Code Playgroud)

c# design-patterns visitor

8
推荐指数
1
解决办法
3330
查看次数

"依赖倒置"和"接口设计"是否遵循相同的原则?

"依赖倒置原则"(DIP)和"设计到接口原理"是否表达了相同的原则?如果没有,那会有什么区别?

编辑

稍微澄清和缩小上下文:通过接口我的意思是编程接口,如Java interface或C++中的纯抽象基类.不涉及其他"合同".

oop dependency-inversion

7
推荐指数
1
解决办法
1085
查看次数

让C++以一种不丑的方式调用正确的模板方法

我正在烹饪一个矢量库并且遇到了障碍.我想允许递归向量(即vec<H,vec<W,T> >),所以我希望我的"min"和其他函数也是递归的.这就是我所拥有的:

template<typename T>
inline T min(const T& k1, const T& k2) {
 return k1 < k2 ? k1 : k2;
}
template<int N, typename T, typename VT1, typename VT2>
inline vec<N,T> min(const container<N,T,VT1>& v1, const container<N,T,VT2>& v2) {
 vec<N,T> new_vec;
 for (int i = 0; i < N; i++) new_vec[i] = min(v1[i], v2[i]);
 return new_vec;
}

...

template<int N, typename T>
class vec : public container<N,T,vec_array<N,T> > {

...

// This calls the first (wrong) method and …
Run Code Online (Sandbox Code Playgroud)

c++ templates

7
推荐指数
1
解决办法
344
查看次数

如何在几秒钟内使用ReSharper创建方法参数对象?

是否可以选择方法的所有参数并要求ReSharper从这些参数创建一个类作为"方法参数对象?"

.net resharper refactoring design-patterns parameter-object

7
推荐指数
1
解决办法
799
查看次数

Objective-C - 模板方法模式?

所以我一直在阅读关于Objective-C的模板方法,我试图了解它们的特殊之处.根据我的理解,Base类中的任何方法都可以被覆盖并且可以调用super吗?那么模板方法不仅仅是覆盖基类中的方法吗?

如果我错了,你能解释一下模板方法模式是什么,你能提供一个例子吗?

design-patterns objective-c template-method-pattern

7
推荐指数
1
解决办法
7903
查看次数

工厂方法VS工厂对象

据我所知,工厂方法是简单工厂,工厂对象是抽象工厂?和:

- 工厂方法(简单工厂):

public class SimplePizzaFactory {
    public static final int CHEESE = 1;
    public static final int PEPPERONI = 2;
    public static final int VEGGIE = 3;

    public static Pizza createPizza(int type) {
        Pizza pizza = null;

        if (type == CHEESE) {
            pizza = new CheesePizza();
        } else if (type == PEPPERONI ) {
            pizza = new PepperoniPizza();
        } else if (type == VEGGIE ) {
            pizza = new VeggiePizza();
        }

        return pizza;
    }
}
Run Code Online (Sandbox Code Playgroud)

工厂对象(抽象工厂):

我对吗?

工厂模式的实现有多少,它们的区别是什么?

java design-patterns factory factory-method factory-pattern

7
推荐指数
1
解决办法
2768
查看次数

teamcity以特定用户身份运行构建

我需要在特定用户ID下的配置上执行构建.我怎样才能做到这一点?我无法切换代理服务作为此用户ID运行,因为我只需要为此特定配置使用此用户或生产ID.我怎么能在Teamcity中做到这一点?

teamcity build

7
推荐指数
1
解决办法
5667
查看次数