using an interface to hide parts of a class that you don't want certain users to call. - CSharp Custom Type

CSharp examples for Custom Type:interface

Description

using an interface to hide parts of a class that you don't want certain users to call.

Demo Code

using System;/*from ww  w .  jav  a2s. c  o  m*/
class Program
{
   public class Rectangle : Shape
   {
      public void GetArea()                        // Safe.
      {
         Console.WriteLine("Rectangle: Climbing stairs.");
      }
      public void Draw()                      // Safe? Might break it.
      {
         Console.WriteLine("Rectangle: Petting the nice doggie.");
      }
      public void Charge() { }
      public void Move() { }
      public void Paint() { }
      public static Shape CreateRectangle()
      {
         return (Shape)new Rectangle();
      }
   }
   public interface Shape
   {
      void GetArea();
      void Draw();
   }
   static void Main(string[] args)
   {
      Shape myZilla = Rectangle.CreateRectangle();
      myZilla.GetArea();
      myZilla.Draw();
   }
}

Result


Related Tutorials