我有两个项目:A和B应该相互交互.
项目A介绍接口名称ISpecialTask和项目B应该实现它.
Projet B有一个名为TaskWithListOfProperties的实体,它不能实现ISpecialTask,因为它具有不同的属性结构(此外,所有系统都知道如何使用TaskWithListOfProperties并且我不想更改其结构).
所以我决定创建一个名为SpecialTaskFromListOfProperties的类,它实现了ISpecialTask并使用TaskWithListOfProperties实例,以便将它用于项目之间的交互.
interface ISpecialTask {
long Id{get;}
long WorkerId{get;}
long VehicleId{get;}
long CustomerId{get;}
}
class TaskWithListOfProperties {
IDictionary<string, long> Properties {get;
}
class SpecialTaskFromListOfProperties : ISpecialTask {
public SpecialTaskFromListOfProperties(TaskWithListOfProperties ins) {
...
...
}
public long Id { get{ ... } }
public long WorkerId { get{ ... } }
public long VehicleId { get{ ... } }
public long CustomerId { get{ ... } }
}
Run Code Online (Sandbox Code Playgroud)
SpecialTaskFromListOfProperties实际上是适配器模式吗?
适配器模式和装饰器模式有什么区别?