【问题标题】:Design a word processor设计一个文字处理器
【发布时间】:2013-06-27 21:36:55
【问题描述】:

我遇到了一个面试问题,要求设计一个文字处理器。

经过研究,我发现享元设计模式是一种方法。我想出了下面的代码(忽略语法)。但是我很难思考什么是我的关键,什么是我对文字处理器的价值。 公开课形式 { 公共只读字符串_fontname; 公共只读字符串_weight; public readonly int _size;

    public Format(string fontname, string weight, string size)
    {
        _fontname = fontname;
        _weight = weight;
        _size = size;
    }
}

public class TextFromatInfo
{
    public _readonly Format _oFormat
    public TextFormatInfo ( Format oformat)
    {
        _oFormat = oFormat;
    }
    public Format GetFormat
    {
        get {return this._oFormat}
    }

    public void ApplyFormat(format Format)
    {
        console.writeline ("apply format fontname: " format.forntname +
           "size: " +  format.size + "weight : " format.weight
    }
}

public class TextFormatFactory
{
    public readonly IDictionary<Format, TextFormatInfo> _cache =
       new Dictionary <Format, TextFormatInfo>

    public TextFormatInfo GetTextFormatInfo(Format oFormat)
    {
        if (_cache.ContainsKey(oFormat)) return _cache[oFormat];
        var OTextFormatInfo= new TextFormatInfo(oFormat);
        _cache.add(OTextFormatInfo.GetFormat, OTextFormatInfo);
        return OTextFormatInfo ;
    }
}

public class TestFlyWeight
{
    private static TextFormatInfo[] formtInfo = new TextFormatInfo[100];
    private static TextFormatFactory ff;

    public void ProcessesWord(char c, string fontname, int size, string weight)
    {
    }
}

上面的类会是什么样子?如何通过实际处理word来完成程序?

【问题讨论】:

    标签: java design-patterns flyweight-pattern


    【解决方案1】:

    老实说,我认为他们对模式的兴趣可能不如对建筑的兴趣。但你可能已经提供了足够的材料让他们消化。

    我想说 MDI 是这里的一个关键主题:多文档界面。带有多个文档的多个选项卡。 每个文件系统文件有一个 Document 对象(两次打开同一个文件),并且每个 Document 可能有多个 DocumentViews(swing:JTextPanes),由 DocumentListener 桥接。在不同的选项卡或垂直拆分的单个选项卡中,因此您可以滚动到另一个位置,但仍保留在拆分窗格中的第一个位置。 _特别强调,这是se

    也许构建 swing 的 EditorKit 和 StyledDocument。

    所以要说明 UI 知识、创造力、功能、现有类。

    这一切都说明了,模式也是面试中的一项重要资产,我亲身经历过。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-22
      • 1970-01-01
      • 2016-08-18
      • 1970-01-01
      • 2010-09-06
      • 2021-12-16
      • 2018-11-21
      相关资源
      最近更新 更多