Click here to Skip to main content
15,885,954 members
Home / Discussions / C#
   

C#

 
GeneralRe: data is not permanent in the database Pin
Member 98700588-Mar-13 10:16
Member 98700588-Mar-13 10:16 
AnswerRe: data is not permanent in the database Pin
Dave Kreskowiak8-Mar-13 11:51
mveDave Kreskowiak8-Mar-13 11:51 
GeneralRe: data is not permanent in the database Pin
Member 98700588-Mar-13 14:04
Member 98700588-Mar-13 14:04 
GeneralRe: data is not permanent in the database Pin
Richard MacCutchan8-Mar-13 21:57
mveRichard MacCutchan8-Mar-13 21:57 
QuestionWhen to use & when not to use ( Abstract Class & Interface ) Pin
Krishna Varadharajan8-Mar-13 2:01
Krishna Varadharajan8-Mar-13 2:01 
AnswerRe: When to use & when not to use ( Abstract Class & Interface ) Pin
Pete O'Hanlon8-Mar-13 2:13
mvePete O'Hanlon8-Mar-13 2:13 
GeneralRe: When to use & when not to use ( Abstract Class & Interface ) Pin
Krishna Varadharajan8-Mar-13 2:59
Krishna Varadharajan8-Mar-13 2:59 
GeneralRe: When to use & when not to use ( Abstract Class & Interface ) Pin
Keith Barrow8-Mar-13 3:22
professionalKeith Barrow8-Mar-13 3:22 
Sorry to steal Pete's thunder.


You can't use an interface for the implementation of common functionality, all an interface does is define what is available not how it is actually achieved. Lets take a simple example, modelling a cats which can for simplicity only look around or make a noise the Interface would look like:

C#
public interface IFeline
{
   LookAround();
   MakeNoise();
}


OK, lets say I want to model a Tiger and a Cat. Both Implement IFeline, both look around in the same way, but a cat purrs but a Tiger roars. LookAround is common to both and should be in a base class. I don't ever want to create and instance of the base class, so I create an abstract one which encapsulate what is common:

C#
public abstract class Feline: IFeline
{
    public LookAround()
    {
        Console.WriteLine("Looking");
    }
    

    public abstract MakeNoise(); //This is needed to stop the compiler complaing
}


Now I can implement the differing functionality:

ch
public class Cat: Feline
{
    public MakeNoise()
    {
        Console.WriteLine("Purrr");
    }
}

public class Tiger: Feline
{
    public MakeNoise()
    {
        Console.WriteLine("Roar");
    }
}


Hope this helps!

GeneralRe: When to use & when not to use ( Abstract Class & Interface ) Pin
Krishna Varadharajan8-Mar-13 3:41
Krishna Varadharajan8-Mar-13 3:41 
GeneralRe: When to use & when not to use ( Abstract Class & Interface ) Pin
Keith Barrow8-Mar-13 4:30
professionalKeith Barrow8-Mar-13 4:30 
GeneralRe: When to use & when not to use ( Abstract Class & Interface ) Pin
Krishna Varadharajan8-Mar-13 4:40
Krishna Varadharajan8-Mar-13 4:40 
GeneralRe: When to use & when not to use ( Abstract Class & Interface ) Pin
Keith Barrow8-Mar-13 4:49
professionalKeith Barrow8-Mar-13 4:49 
AnswerRe: When to use & when not to use ( Abstract Class & Interface ) Pin
GuyThiebaut8-Mar-13 2:40
professionalGuyThiebaut8-Mar-13 2:40 
GeneralRe: When to use & when not to use ( Abstract Class & Interface ) Pin
Krishna Varadharajan8-Mar-13 3:04
Krishna Varadharajan8-Mar-13 3:04 
GeneralRe: When to use & when not to use ( Abstract Class & Interface ) Pin
GuyThiebaut8-Mar-13 3:28
professionalGuyThiebaut8-Mar-13 3:28 
GeneralRe: When to use & when not to use ( Abstract Class & Interface ) Pin
Krishna Varadharajan8-Mar-13 3:57
Krishna Varadharajan8-Mar-13 3:57 
GeneralRe: When to use & when not to use ( Abstract Class & Interface ) Pin
GuyThiebaut8-Mar-13 4:16
professionalGuyThiebaut8-Mar-13 4:16 
GeneralRe: When to use & when not to use ( Abstract Class & Interface ) Pin
Krishna Varadharajan8-Mar-13 4:57
Krishna Varadharajan8-Mar-13 4:57 
AnswerRe: When to use & when not to use ( Abstract Class & Interface ) Pin
PIEBALDconsult8-Mar-13 3:42
mvePIEBALDconsult8-Mar-13 3:42 
AnswerRe: When to use & when not to use ( Abstract Class & Interface ) Pin
Shameel8-Mar-13 4:08
professionalShameel8-Mar-13 4:08 
GeneralRe: When to use & when not to use ( Abstract Class & Interface ) Pin
Krishna Varadharajan8-Mar-13 4:33
Krishna Varadharajan8-Mar-13 4:33 
GeneralRe: When to use & when not to use ( Abstract Class & Interface ) Pin
Shameel8-Mar-13 5:01
professionalShameel8-Mar-13 5:01 
GeneralRe: When to use & when not to use ( Abstract Class & Interface ) Pin
Krishna Varadharajan8-Mar-13 5:53
Krishna Varadharajan8-Mar-13 5:53 
AnswerRe: When to use & when not to use ( Abstract Class & Interface ) Pin
jschell8-Mar-13 12:41
jschell8-Mar-13 12:41 
QuestionWhy SqlCommandBuilder Pin
Krishna Varadharajan8-Mar-13 1:50
Krishna Varadharajan8-Mar-13 1:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.