This is an follow up discussion on the previous impl of the c# - design of generic version of interface with its non generic verion. In this example, I will introduce a more real world like example (however, stil this code need to be improved).
First is the declarations of the interfaces.
// boqwang: [placeholder] // better to call "Duplexer"? interface IProfilePersistenceProxy { void HookPersistenceEvent(IPersistableStateOwner stateOwner); } interface IProfilePersistenceProxy<T> : IProfilePersistenceProxy { void HookPersistenceEvent(IPersistableEnumerableStateOwner<T> stateOwner); }
and below is class definition
// boqwang: [placeholder] class RamboProfilePersistenceProxy : // boqwang - IProfilePersistenceProxy { protected internal WpfApplicationPersistence persistence; public RamboProfilePersistenceProxy( WpfApplicationPersistence appPersistence ) { this.persistence = appPersistence; } public virtual void HookPersistenceEvent(IPersistableStateOwner stateOwner) { // boqwang - Q? // is it possible to determine if a if (stateOwner == null) throw new ArgumentNullException("stateOwner"); Trace.WriteLine("RamboProfilePersistenceProxy"); Type type = stateOwner.GetType(); if (type.GetGenericTypeDefinition() == typeof(IPersistableEnumerableStateOwner<>)) { // .... } throw new NotImplementedException(); } } class RamboProfilePersistenceProxy<T> : RamboProfilePersistenceProxy, IProfilePersistenceProxy<T>, IProfilePersistenceProxy { public RamboProfilePersistenceProxy( WpfApplicationPersistence appPersistence ) : base(appPersistence) { } public override void HookPersistenceEvent(IPersistableStateOwner stateOwner) { Trace.WriteLine("RamboProfilePersistenceProxy<T>"); if (stateOwner is IPersistableEnumerableStateOwner<T>) { HookPersistenceEvent((IPersistableEnumerableStateOwner<T>) stateOwner); } else { base.HookPersistenceEvent(stateOwner); } } void IProfilePersistenceProxy.HookPersistenceEvent(IPersistableStateOwner stateOwner) { this.HookPersistenceEvent(stateOwner); } public void HookPersistenceEvent(IPersistableEnumerableStateOwner<T> stateOwner) { if (stateOwner == null) throw new ArgumentNullException("stateOwner"); stateOwner.StateSaving += new EventHandler<PersistableEnumerableStateSavingEventArgs<T>>(stateOwner_StateSaving); stateOwner.StateLoaded += new EventHandler<PersistableEnumerableStateLoadedEventArgs<T>>(stateOwner_StateLoaded); if (persistableStateOwners.FirstOrDefault(p => p.GetType() == stateOwner.GetType()) == null) { persistableStateOwners.Add(stateOwner); } // - boqwang: silently/quitely/noiselessly/soundlessly/stillnessly ignore. } List<IPersistableStateOwner> persistableStateOwners = new List<IPersistableStateOwner>(); void stateOwner_StateLoaded<T>(object sender, PersistableEnumerableStateLoadedEventArgs<T> e) { throw new NotImplementedException(); } void stateOwner_StateSaving<T>(object sender, PersistableEnumerableStateSavingEventArgs<T> e) { throw new NotImplementedException(); } }
The things that I wantted to highlight here is that the Generic class has impl both the the generic interface and the non-generic interface, also it tries to override the interfaces that is inherited from its base classs, a non-generic class.
相关推荐
matplotlib-3.6.3-cp39-cp39-linux_armv7l.whl
numpy-2.0.1-cp39-cp39-linux_armv7l.whl
基于springboot个人公务员考试管理系统源码数据库文档.zip
onnxruntime-1.13.1-cp310-cp310-win_amd64.whl
基于springboot的西山区家政服务网站源码数据库文档.zip
Linux环境下,关于C++静态库的封装和调用代码。 TestLib是库目录。 TestLibCall是调用库的目录。
基于springboot软件技术交流平台源码数据库文档.zip
numpy-1.20.1-cp39-cp39-linux_armv7l.whl
ASP.NET酒店管理系统源码(WPF) 一、源码特点 采用WPF进行开发的酒店管理系统源码,界面相当美观,功能齐全 二、菜单功能 1、预订登记:可选择入住时间、离店时间、所在城市、证件类型,保存、删除、查询、返回 2、住宿结算:新增入住、保存、删除、查询、返回 3、今日盘点:查询、返回 4、查询统计: 5、房间管理:增加房间类型、删除类型、增加房间、删除房间、保存、返回 6、用户管理:增加用户、删除用户、保存、返回 7、系统配置:基本功能 8、显示当前系统时间等功能的实现
坠落的天空小游戏图片和代码
论文描述:该论文研究了某一特定领域的问题,并提出了新的解决方案。论文首先对问题进行了详细的分析和理解,并对已有的研究成果进行了综述。然后,论文提出了一种全新的解决方案,包括算法、模型或方法。在整个研究过程中,论文使用了合适的实验设计和数据集,并进行了充分的实验验证。最后,论文对解决方案的性能进行了全面的评估和分析,并提出了进一步的研究方向。 源码内容描述:该源码实现了论文中提出的新的解决方案。源码中包含了算法、模型或方法的具体实现代码,以及相关的数据预处理、实验设计和性能评估代码。源码中还包括了合适的注释和文档,以方便其他研究者理解和使用。源码的实现应该具有可读性、可维护性和高效性,并能够复现论文中的实验结果。此外,源码还应该尽可能具有通用性,以便在其他类似问题上进行进一步的应用和扩展。
环境说明: 开发语言:python Python版本:3.6.8 数据库:mysql 5.7 数据库工具:Navicat11 开发软件:pycharm
基于springboot高校学术交流平台源码数据库文档.zip
onnxruntime-1.16.2-cp310-cp310-win_amd64.whl
基于springboot+vue的实践性教学系统源码数据库文档.zip
基于springboot的校园二手物品交易系统源码数据库文档.zip
numpy-1.23.5-cp39-cp39-linux_armv7l.whl
bimdata_api_client-4.0.2-py3-none-any.whl
环境说明: 开发语言:PHP 框架:原生php/thinkphp5 服务器:Apache 数据库:mysql 5.7(一定要5.7版本) 数据库工具:Navicat 11 运行软件:小皮phpStudy
基于SpringBoot的中老年人文化活动平台源码数据库文档.zip