Sunday, March 13, 2016

Abstraction And Information Hiding

One day I will have my own Mobile OS Company :)

An application for mobile manufacturing company - Every phone must have to implement caller
and sms feature but it depends on company to company (or model to model) if they want to include other features or not which are readily available , you just have to use it without knowing its implementation (like facebook in this example).

Below Code in C#.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AbstractTest
{
    public abstract class feature {
        public abstract void Caller();
        public abstract void SMS();
        public void facebook(){
            Console.WriteLine("You are using facebook");
        }
    }
    public class Iphone : feature
    {
        public override void Caller(){
            Console.WriteLine("iPhone caller feature");
        }
        public override void SMS(){
            Console.WriteLine("iPhone sms feature");
        }
        public void otherFeature(){
            facebook();
        }
    }
    public class Nokia : feature
    {
        public override void Caller(){
            Console.WriteLine("Nokia caller feature");
        }
        public override void SMS(){
            Console.WriteLine("Nokia sms feature");
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Iphone c1 = new Iphone();
            c1.Caller();
            c1.SMS();
            c1.otherFeature();
            Nokia n1 = new Nokia();
            n1.Caller();
            n1.SMS();
            Console.ReadLine();
        }
    }
}

No comments:

Post a Comment