相关疑难解决方法(0)

访客模式示例

public class Song {
    public string Genre { get; protected set; }
    public string Name { get; protected set; }
    public string Band { get; protected set; }

    public Song(string name, string band, string genre) {
        Name = name;
        Genre = genre;
        Band = band;
    }
}

public interface IMusicVisistor
{
    void Visit(List<Song> items);
}

public class MusicLibrary {
    List<Song> _songs = new List<Song> { ...songs ... };

    public void Accept(IMusicVisitor visitor) {
        visitor.Visit(_songs);
    }
}
Run Code Online (Sandbox Code Playgroud)

现在这是我做的一位访客:

public class RockMusicVisitor …
Run Code Online (Sandbox Code Playgroud)

c# oop design-patterns

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

标签 统计

c# ×1

design-patterns ×1

oop ×1