首页 > 代码库 > 链式生产环境装配
链式生产环境装配
链式生产环节装配:
/// <summary> /// 数据,它会反复接收工厂里各个环节的加工 /// </summary> public class DataStream { public string Status { get; set; } }
/// <summary> /// 节点抽象类,模拟各种机器 /// </summary> /// <typeparam name="T"></typeparam> public abstract class MechineNode<T> : IMechine<T> where T : DataStream, new() { public IMechine<T> Next { get; set; } public T Data { get; set; } public abstract IMechine<T> Execute(); public IMechine<T> Append(IMechine<T> next) { this.Next = next; next.Data = http://www.mamicode.com/this.Data;>
/// <summary> /// 机器节点1 /// </summary> /// <typeparam name="T"></typeparam> public sealed class Mechine1<T> : MechineNode<T> where T : DataStream, new() { public override IMechine<T> Execute() { this.Data.Status = "updated by mechine 1"; return this; } }
/// <summary> /// 机器节点2 /// </summary> /// <typeparam name="T"></typeparam> public sealed class Mechine2<T> : MechineNode<T> where T : DataStream, new() { public override IMechine<T> Execute() { this.Data.Status += ",updated by mechine 2"; return this; } }
下面是应用:
DataStream data = http://www.mamicode.com/new DataStream();>
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。