【问题标题】:Design pattern to save the same data to different file formats将相同数据保存到不同文件格式的设计模式
【发布时间】:2012-05-18 04:51:47
【问题描述】:

我有一个 3D 动画,我想输出为不同的文件格式,例如 .BVH、.FBX...

适合实现这种功能的设计模式是什么?

工厂设计模式行得通吗?为什么和为什么不。

谢谢

【问题讨论】:

标签: design-patterns factory


【解决方案1】:

我认为重要的是设计而不是图案名称。我认为您需要的是一种适配器:

public interface IAnimationFormat {
    void Save(Animation animation);
}

public class Bvh : IAnimationFormat {
    public void Save(Animation animation){
        ...
    }
}

public class Fbx : IAnimationFormat {
    public void Save(Animation animation){
        ...
    }
}

您还可以添加 Load 方法和东西。

【讨论】:

    【解决方案2】:

    它既不是 Builder 也不是 Factory。它看起来像Strategy pattern

    【讨论】:

    【解决方案3】:

    对于这种情况,您应该考虑 BuilderFactory 模式。

    【讨论】:

      【解决方案4】:

      我会使用观察者模式。假设您有可观察的 A 类和观察者 C 和 D 类。 单击 A、raise 和 event 上的 SAVE 以通知 B、C、......任何更多的观察者执行 SAVE 操作。

      http://www.dofactory.com/Patterns/PatternObserver.aspx

      【讨论】:

        猜你喜欢
        • 2011-10-24
        • 2010-09-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-10-29
        • 1970-01-01
        • 2014-06-13
        • 1970-01-01
        相关资源
        最近更新 更多