是否允许类在 C# 中实现接口和额外的私有方法?

您所在的位置:网站首页 银行软件不允许截屏 是否允许类在 C# 中实现接口和额外的私有方法?

是否允许类在 C# 中实现接口和额外的私有方法?

2023-04-26 19:54| 来源: 网络整理| 查看: 265

文江博客话题详情C# interface private-methods interface-implementation是否允许类在 C# 中实现接口和额外的私有方法?发布于 2022-10-12 17:39:58 字数 797 浏览 4 评论 0原文

我有以下接口:

interface IExcelServices { Dictionary FilterFields(Dictionary excelContent); Dictionary ParseExcelFile(string path); }

由以下类实现:

public class ExcelServices : IExcelServices { public Dictionary FilterFields(Dictionary excelContent) { //somecode } public Dictionary ParseExcelFile(string path) { //somecode } private void ReleaseObject(object obj) { //somecode } }

我的代码编译没有任何问题,但我想知道是否添加私有方法 (或通常任何方法)不在接口定义中的是良好的 OO 编程实践还是不是。

原文

I have the following interface:

interface IExcelServices { Dictionary FilterFields(Dictionary excelContent); Dictionary ParseExcelFile(string path); }

Which is implemented by the following class:

public class ExcelServices : IExcelServices { public Dictionary FilterFields(Dictionary excelContent) { //somecode } public Dictionary ParseExcelFile(string path) { //somecode } private void ReleaseObject(object obj) { //somecode } }

My code compiles without any problem but I was wondering whether adding a private method (or in general any method) which is not in the interface definition is a good OO programming practice or not.

收藏 0 分享到微信 分享到QQ 分享到微博如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。扫码二维码加入Web技术交流群


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3