抽象与界面 [英] Abstraction vs Interface

查看:70
本文介绍了抽象与界面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我在这个主题中有一个小小的混乱抽象与界面任何人都可以帮助我。



我听说界面中有哪些方法都是公共抽象的本质!



类似于抽象类我可以声明抽象方法并在子类中定义它。



当我在子类中定义它时,我需要覆盖它。为什么不用这个东西需要



接口的情况因为接口还包含抽象方法?



我还想知道抽象和封装之间的区别是什么?



 摘要  class  abschandan 
{
public abstract void add ();
public void sub()
{
Console.Write( dfg);
}
}
class chandan:abschandan
{
public 覆盖 void add ()
{
Console.Write( hi);
}
}









谢谢

-------

Vamsi krishna

解决方案

我听说那是什么在界面中它们是公共抽象的方法!



不,它们不是。

接口中定义的方法不能是 abstract - 除了派生类之外,它们永远不会有任何形式的实现,绝对 必须 实现接口类中声明的所有方法。



Abstract类中定义的方法可以具有 可能的实现 在派生类中重写并实现,但不一定是。如果不是那么使用基类版本。



抽象和封装无法比较:它们没有严格的关联,甚至没有尝试做同样的工作!



封装隐藏了实现细节,并在顶部提供了一层代码来访问它 - 类的外部使用者无法与封装的交互直接类,但必须通过嵌入对象的类 - 可能甚至不知道它存在。



抽象提供了一个概括(比方说,一组行为)。



阅读时间:抽象,封装和信息隐藏 [ ^ ]


首先参考这篇文章......



所有关于抽象类的内容。 [ ^ ]



这是Interfaces与Abstract class之间的区别......

抽象类与界面 [ ^ ]



如果你想探索OOP的基本概念,请参考这篇文章...

一般我们都知道如何我们可以使用OOP概念(多态性,封装,继承,抽象)但本文将向您展示WHEN& 为什么使用OOP。



这篇文章值得一读......

面向对象的设计原则 [ ^ ]



希望这个帮助你

--------------------

Pratik Bhuva

在抽象类中,您可以同时使用抽象和非抽象方法。

接口不包含任何实现。



尝试所有关于抽象类的内容。 [ ^ ]。


Hi All,

I have a small confusion in this topic "Abstraction vs Interface" can any one help me in this.

I heard that what ever the methods are there in the interface they are public Abstract in nature!

Similarly in an abstract class i can declare abstract methods and define this in the child class.

When i define this in the child class i need to Override this. Why not this thing required in

the case of Interface because interface will also contain the Abstract methods?

And also i want to know what is the differences between Abstraction and Encapsulation?

abstract class abschandan
  {
      public abstract void add();
      public void sub()
      {
          Console.Write("dfg");
      }
  }
  class chandan : abschandan
  {
     public override void add()
      {
          Console.Write("hi");
      }
  }





Thanks
-------
Vamsi krishna

解决方案

"I heard that what ever the methods are there in the interface they are public Abstract in nature!"

No, they aren't.
Methods defined in an Interface cannot be abstract - they never have any form of implementation except in the derived class, which absolutely must implement all methods declared in the interface class.

Methods defined in an Abstract class can have an implementation which may be overridden and implemented in a derived class, but doesn't have to be. If it isn't then the base class version is used.

Abstraction and encapsulation can't be compared: they are not strictly related, and do not even try to do the same job!

Encapsulation hides the implementation details and provides a layer of code over the top to access it - the external consumer of the class cannot interact with the encapsulated class directly, but must go via the class in which the object is embedded - and probably doesn't even know it exists.

Abstraction is providing a generalization (say, over a set of behaviors).

Time for some reading: Abstraction, Encapsulation, and Information Hiding[^]


First of all Refer this article...

All about abstract classes.[^]

Here is the difference between Interfaces vs Abstract class...
Abstract Class versus Interface[^]

And if you want to explore basic concept of OOP refer this article...
Generally all we know "How" can we use OOP concepts(polymorphism, encapsulation, inheritance, abstaction ) But this Article will show you "WHEN" & "WHY" to use OOP.

This article worth reading...
Object Oriented Design Principles[^]

Hope This Help You
--------------------
Pratik Bhuva


In an abstract class, you can have both abstract and non-abstract methods.
Interfaces do not contain any implementation.

Try All about abstract classes.[^].


这篇关于抽象与界面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆