C# DERS 35: GENERIC

Tip güvenliği ve performans dezavantajları gereğiyle generic kullanılmaktadır.
Sınıf metot ya da temsilci bazında herhangi bir üye elemanın tipinin bildirim aşamasında belli olmadığı
durumlarda da kullanılır.
Class Struct Metot Interface ve delegateler kullanılabilir.

class Program
    {
        static void Main(string[] args)
        {

        }
    }

    class Product
    {
        public string ProductName { get; set; }
    }

    interface IProductDal : IRepository<Product>
    {

    }

    class Customer
    {
        public string CustomerName { get; set; }
    }

    interface ICustomerDal : IRepository<Customer>
    {
        
    }


    // T , sadece reference type olabilir demektir. Eğer  ,new()  eklersek artık new'lenebilir olmalı
    // kısıtı da eklediğinden T artık mesela string olamaz. Çünkü string, reference typedır ancak new'lenemez
    //  where T: struct deseydik bu seferde T, sadece value type olabilir anlamına gelecekti.
    interface IRepository<T> where T: class
    {
        List<T> GetAll();
        T Get(int id);
        void Add(T entity);
        void Delete(T entity);
        void Update(T entity);
    }

    class ProductDal : IProductDal
    {
        public void Add(Product entity)
        {
            throw new NotImplementedException();
        }

        public void Delete(Product entity)
        {
            throw new NotImplementedException();
        }

        public Product Get(int id)
        {
            throw new NotImplementedException();
        }

        public List<Product> GetAll()
        {
            throw new NotImplementedException();
        }

        public void Update(Product entity)
        {
            throw new NotImplementedException();
        }
    }

    class CustomerDal : ICustomerDal
    {
        public void Add(Customer entity)
        {
            throw new NotImplementedException();
        }

        public void Delete(Customer entity)
        {
            throw new NotImplementedException();
        }

        public Customer Get(int id)
        {
            throw new NotImplementedException();
        }

        public List<Customer> GetAll()
        {
            throw new NotImplementedException();
        }

        public void Update(Customer entity)
        {
            throw new NotImplementedException();
        }
    }