Jump to content

class vs interface

- - - - -

  • Please log in to reply
5 replies to this topic

#1
Tonchi

Tonchi

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 471 posts
  • Location:Varaždin
  • Programming Language:C, C++, C#
can someone tell me the difference???

#2
Vaielab

Vaielab

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 547 posts
I cant tell for every single language, but for the one I know, class have code, interface don't.

Interface is a contract. If someone use your interface, they need to create the function that the interface tell them to create.
Class have function and code.

So a class can be on it own, but a interface without any class is nothing.
I use interface mostly when I work on big project with other people and want to be certain that they will implements certains function on all their class. Since a class that don't implemente everything will fail to compile.

#3
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
For C#, you cannot instantiate an interface. They don't have member variables, and they don't implement methods. Interfaces define methods that a class which implements the interface must define.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#4
Tonchi

Tonchi

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 471 posts
  • Location:Varaždin
  • Programming Language:C, C++, C#
some example please

#5
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Do you have a book on C#? It should have numerous examples in it.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#6
sysman

sysman

    Newbie

  • Members
  • Pip
  • 3 posts
A C# Class Considered being the primary building block of the language. What I mean by the primary building block of the language is that every time you work with C# you will create Classes to form a program. We use Classes as a template to put the properties and functionalities or behaviors in one building block for some group of objects and after that we use that template to create the objects we need.

A class can contain declarations of the following members:

Constructors, Destructors, Constants, Fields, Methods, Properties,Indexers, Operators, Events, Delegates, Classes, Interfaces, Structs



An interface contains only the signatures of methods, delegates or events. The implementation of the methods is done in the class that implements the interface. A class that implements an interface can explicitly implement members of that interface. An explicitly implemented member cannot be accessed through a class instance, but only through an instance of the interface.

An interface can inherit from one or more base interfaces. When a base type list contains a base class and interfaces, the base class must come first in the list.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users