标签: composition

如何使用规范测试框架从匹配器[A]中编写匹配器[Iterable [A]]

如果我有一个Matcher [A]如何创建一个Matcher [Iterable [A]],只有当Iterable的每个元素都满足原始Matcher时才会满足.

class ExampleSpec extends Specification {
  def allSatisfy[A](m: => Matcher[A]): Matcher[Iterable[A]] = error("TODO")
  def notAllSatisfy[A](m: => Matcher[A]): Matcher[Iterable[A]] = allSatisfy(m).not    

   "allSatisfy" should {
     "Pass if all elements satisfy the expectation" in {
      List(1, 2, 3, 4) must allSatisfy(beLessThan(5))
    }

    "Fail if any elements do not satisfy the expectation" in {
      List(1, 2, 3, 5) must notAllSatisfy(beLessThan(5))
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

specs scala matcher composition

3
推荐指数
1
解决办法
194
查看次数

关于继承Java类的性质的问题

所以我认为我有一个非常基本的问题.假设您的项目com.bee.buzz中包含一个名为com.cow.moo的开源Java程序.

moo有很多很棒的课程,其中大部分是你不想触摸的,但是有一些你做的.现在,在这一点上,最好的办法是扩展你想要修改的类,对吧?(我知道有很多关于扩展与实现的说法,但这些类都不是接口,所以这是不可能的.)

我的问题是,说这是moo中的类:

package com.cow.moo;
public class Milk {
    private float currentMilk;
    public int getMilk() { /* Stuff */ }
    public float convertToGallons (float liquid) { /* More Stuff */ }
}
Run Code Online (Sandbox Code Playgroud)

现在,假设我想在扩展Milk的新类中使用getMilk.但是,Milk中的getMilk依赖于私有变量(如currentMilk)和其他我不会包含的函数(如convertToGallons.)如果我希望我的新函数正常工作,我是否必须包含其他变量和函数?我不想大量修改函数,只需添加一点就可以了.最好的方法是什么?

一般来说,建立一个更大的项目的提示也是有用的.我认为这里的一些Java专家甚至不会花五秒钟来得出答案.谢谢你的时间.

java oop inheritance composition

3
推荐指数
1
解决办法
169
查看次数

初始化scala中特征内的特征

Scala in Depth中有这样的例子:

trait Logger {
  def log(category: String, msg: String) : Unit = {
       println(msg)
  }
}

trait DataAccess {
  def query[A](in: String) : A = {
     ...
  }
}

trait LoggedDataAccess {
  val logger = new Logger
  val dao = new DataAccess

  def query[A](in: String) : A = {
     logger.log("QUERY", in)

     dao.query(in)
  }
}
Run Code Online (Sandbox Code Playgroud)

我对Traget LoggedDataAccess中Logger和DataAccess的初始化感到有些困惑.在REPL中,当我输入此代码时,我得到以下异常:

 error: trait Logger is abstract; cannot be instantiated
       val logger = new Logger
Run Code Online (Sandbox Code Playgroud)

实际上可以像这样初始化特征吗?

scala traits composition

3
推荐指数
1
解决办法
504
查看次数

Haskell,算法所有可能的编号组成

我在haskell中有一个代码,它生成数字的三部分组合:

kompozycje n = [ (x,y,z) | x<-[1..n], y<-[1..n], z<-[1..n], x+y+z==n]
Run Code Online (Sandbox Code Playgroud)

我想制作类似kompozycje nk的东西,它会生成我的k-part组合,然后如果例如k等于4则会有四个变量和四个数字返回,并且在条件下会有类似u + x + y + z的东西==ñ.有一些简单的解决方案吗?

haskell numbers combinatorics composition

3
推荐指数
1
解决办法
323
查看次数

OOP组成

我有一个关于OOP成分的问题.

假设一位母亲有0或更多的孩子,而且一个孩子只有一个生物学母亲.

为了说明这一点,我做了以下事情:

public class Mother : ObservableObject
{
    // [...]

    ObservableCollection<Child> Children {get; set;}
}

public class Child : ObservableObject
{
    public Child(Mother mother)
    {
        this.Mother = mother;

        // Adding the child to the mother's children collection
        mother.Children.Add(this);
    }

    public Mother Mother {get; set;}
}
Run Code Online (Sandbox Code Playgroud)

但我想知道是否可以自动将孩子添加到母亲的收藏中,或者我是否应该使用以下内容:

Mother mother = new Mother();

Child child = new Child(mother);
mother.Children.Add(child);
Run Code Online (Sandbox Code Playgroud)

谢谢 :)

c# oop composition

3
推荐指数
1
解决办法
134
查看次数

使用扩展脚本在后效应项目中按名称获取合成

我正在研究After Effects脚本并使用AE脚本指南作为学习的基础.

我有一个After Effect项目,其中包含两个AE项目,每个项目中都有多个项目.

我想从具有特定名称的主项目中获取合成但不循环遍历项目中的所有项目.例如,

var myComp = app.project.comp("Composition Name");
Run Code Online (Sandbox Code Playgroud)

这可能吗 ?还有其他方法吗?

after-effects extendscript composition

3
推荐指数
1
解决办法
4172
查看次数

为什么在python中使用工厂方法?

我在openstack中子读了下面的代码.

class APIRouter(wsgi.Router):

    @classmethod
    def factory(cls, global_config, **local_config):
        return cls(**local_config)

    def __init__(self, **local_config):
        # do something. Not using local_config
Run Code Online (Sandbox Code Playgroud)

我这里有两个问题.

  1. 从工厂代码我们可以知道它用于创建APIRouter实例.但为什么我们需要呢?为什么我们不只是api_router = ApiRouter()用来获取实例?

  2. __init__和工厂,local_configglobal_config没有使用.为什么我们在功能中定义它?

我想使用工厂而不是构造函数应该有一些优势.就像JAVA中的设计模式一样.我希望答案可以说明优势或原因.更好的一些exapmle

python plugins factory composition openstack-neutron

3
推荐指数
1
解决办法
970
查看次数

UWP视觉偏移动画不起作用

对于我的应用程序,我希望能够使用Composition API为UIElement的Offset设置动画这个元素是在Xaml中预定义的,我发现这些控件的Visual层只能在触发动画计算...

此行为导致动画仅在第二次调用时显示

我的Xaml

<StackPanel x:Name="ActionButtonsPanel" Margin="50,175,0,0" HorizontalAlignment="Left" VerticalAlignment="Top">
    <Button x:Name="CreateNewButton" Tag="&#xE160;" Content="Create New..." Style="{StaticResource IconButtonStyle}" Click="CreateNewButton_Click"/>
    <Button x:Name="OpenFileButton" Tag="&#xE838;" Content="Open File..." Style="{StaticResource IconButtonStyle}" Margin="0,10,0,0" Click="OpenFileButton_Click"/>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)

我的守则

private void ShowNextButtons(UIElement Item1, UIElement Item2) {
    var _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;

    var visual1 = ElementCompositionPreview.GetElementVisual(Item1);
    visual1.CenterPoint = new Vector3(0, (float) Item1.RenderSize.Height / 2F, 0);

    var animationGroup1 = _compositor.CreateAnimationGroup();

    var offset1 = visual1.Offset; //First Time: Offset = <0,0,0>

    var fadeOut = _compositor.CreateScalarKeyFrameAnimation();
    fadeOut.Target = "Opacity";
    fadeOut.Duration = TimeSpan.FromMilliseconds(1000);
    fadeOut.InsertKeyFrame(0, 1);
    fadeOut.InsertKeyFrame(1, …
Run Code Online (Sandbox Code Playgroud)

c# composition uwp

3
推荐指数
1
解决办法
439
查看次数

在Azure功能应用程序中使用MEF

我想在我的功能应用程序中使用MEF.我的要求是访问5-10个外部API,通过HTTP触发的函数获取,聚合和返回数据.我需要根据某些逻辑动态地解决外部依赖关系.这些外部组件已经构建和导出.我需要将它们与元数据一起导入.

我发现 System.ComponentModel.Composition在VS 2017中创建的默认功能应用程序中已经引用了程序集.不确定如何继续.如果可以在Azure功能中使用,则示例设置代码将非常有用.

c# mef composition azure azure-functions

3
推荐指数
1
解决办法
380
查看次数

组成和泛型

我正在尝试解决这个"组合+泛型"情况,并使PostCompany.send(msg)与传递/注入类的类型兼容.

我可以更改什么以允许Fedex和FedexPlus在PostCompany类中用作泛型类型,因为Fexed的send方法需要String作为参数而FeexPlus需要Integer?

interface Poster<T> {
    void send(T msg);
}

class Fedex implements Poster<String> {

    @Override
    public void send(String msg) {
        // do something
    }
}

class FedexPlus implements Poster<Integer> {

    @Override
    public void send(Integer msg) {
        // do something
    }
}

class PostCompany<P extends Poster> {

    private final P poster;

    public PostCompany(P poster) {
        this.poster = poster;
    }

    public void send(??? msg) { // <-- Here 
        this.poster.send(msg);
    }
}
Run Code Online (Sandbox Code Playgroud)

java oop generics composition

3
推荐指数
1
解决办法
116
查看次数