looking for exercises to practice interfaces on c#
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: looking for exercises to practice interfaces on c#

  1. #1
    Join Date
    Sep 2013
    Posts
    16

    looking for exercises to practice interfaces on c#

    i`m new at c# and i have learned about the interfaces subject so i am looking for a little project that i can do , that i will need to use interface , so i will understand this subject better
    if some one have a pdf from scool or uni with exercises i`ll be happy to get it

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,254

    Re: looking for exercises to practice interfaces on c#

    Search bing or google for "C# interface tutorial".

  3. #3
    Join Date
    Sep 2007
    Posts
    82

    Re: looking for exercises to practice interfaces on c#

    In general if you are wanting to understand interfaces. I say just get in there spin up a simple console application and give it a try.

    An interface is nothing more than a contract between it and its implementer. So basically the interface is saying "hey you implementer, you have to have this method, field, etc...I don't care what you do with it but you have to have it."

    Code:
    //interface
    public interface IMyInterface 
    {
      string MyMethod();
    }
    
    //implementer 1
    public class MyInterfaceImplementer : IMyInterface
    {
        public string MyMethod()
        {
           return "My First String";
         }
    }
    
    //implementer 2
    public class MyInterfaceImplementer2 : IMyInterface
    {
       public string MyMethod()
       {
            return "My 2nd string";
        }
    }
    
    //main - pseudo-code
    static void Main()
    {
        IMyInterface iTest = null; 
        iTest =  new MyInterfaceImplementer();
        var value1 = iTest.MyMethod();
        //value1 will be "My First String"
       
       iTest = new MyInterfaceImplementer2()
       var value2 = iTest.MyMethod();
       //value 1 will be "My 2nd string"
    }

    so you can see that iTest is of type IMyInterface but since both classes implement IMyInterface we can use the same variable when declaring a new instance of each class. But they return different values when calling the same method.

    hope this helps...

    -zd

  4. #4
    Join Date
    Feb 2013
    Location
    Canada
    Posts
    51

    Re: looking for exercises to practice interfaces on c#

    Write a plugin wrapper. Possibly one of the best scenarios where an interface is used.

    Microsoft MVP .NET Programming (2012 - Present)
    ®Crestron DMC-T Certified Automation Programmer

  5. #5
    Join Date
    Jan 2010
    Posts
    1,099

    Re: looking for exercises to practice interfaces on c#

    To understand interfaces you first need to have at least some idea of the concept of type abstraction (generalisation), type derivation and specialization, and inheritance in object-oriented programming (both interface inheritance and implementation inheritance). Knowing a bit about composition doesn't hurt as well. Are you familiar with any of these things? If not, start by learning what classes and objects are, and how they interact together, and worry about interfaces later. Interfaces are all about making this interaction possible, maintainable, and flexible.

  6. #6
    Join Date
    Feb 2013
    Location
    Canada
    Posts
    51

    Re: looking for exercises to practice interfaces on c#

    You should be able to develop a console based (or text style) game using interfaces as well, as long as you take on a good OO model for the design. You can write a strictly procedural game as well, so it's for the most part awareness of what you're doing with your objects that would make the difference. Inheritance from base classes, and interfaces for perhaps how each enemy interacts or behaves would be a good setup.

    Microsoft MVP .NET Programming (2012 - Present)
    ®Crestron DMC-T Certified Automation Programmer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center