Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 设计一个字处理器_Java_Design Patterns_Flyweight Pattern - Fatal编程技术网

Java 设计一个字处理器

Java 设计一个字处理器,java,design-patterns,flyweight-pattern,Java,Design Patterns,Flyweight Pattern,我在面试中遇到一个问题,要求设计一个文字处理器 经过研究,我发现Flyweight设计模式是一种方法。我想出了下面的代码(忽略语法)。但我很难思考什么是我的关键,什么是我对文字处理器的价值。 公共类格式 { 公共只读字符串_fontname; 公共只读字符串_-weight; 公共只读整数大小 public Format(string fontname, string weight, string size) { _fontname = fontname;

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

经过研究,我发现Flyweight设计模式是一种方法。我想出了下面的代码(忽略语法)。但我很难思考什么是我的关键,什么是我对文字处理器的价值。 公共类格式 { 公共只读字符串_fontname; 公共只读字符串_-weight; 公共只读整数大小

    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)
    {
    }
}
公共格式(字符串名称、字符串重量、字符串大小)
{
_fontname=fontname;
_重量=重量;
_大小=大小;
}
}
公共类TextFromatInfo
{
公共格式(只读格式)
公共文本格式信息(格式信息)
{
_oFormat=oFormat;
}
公共格式GetFormat
{
获取{返回此。_offormat}
}
公共无效应用程序格式(格式)
{
console.writeline(“应用格式fontname:”format.forntname+
“尺寸:”+format.size+“重量:”.format.weight
}
}
公共类文本格式工厂
{
公共只读IDictionary\u缓存=
新词典
公共文本格式信息GetTextFormatInfo(格式为Format)
{
if(_cache.ContainsKey(oFormat))返回_cache[oFormat];
var OTextFormatInfo=新的TextFormatInfo(oFormat);
_add(OTextFormatInfo.GetFormat,OTextFormatInfo);
返回OTextFormatInfo;
}
}
公共级试飞重量
{
私有静态TextFormatInfo[]formtInfo=新TextFormatInfo[100];
私有静态文本格式;
public void ProcessesWord(字符c、字符串fontname、整数大小、字符串权重)
{
}
}

上面的课程是什么样子的?我怎样才能通过实际处理单词来完成这个程序呢?

老实说,我认为他们可能对模式不太感兴趣,而对架构感兴趣。但是你可能已经给了他们足够的材料让他们消化

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

也许是建立swing的EditorKit和StyledDocument

因此,要强调UI知识、创造力、功能和现有类

总之,模式也是面试中的一项重要资产,我有过这样的经历