static void Main(string[] args) { Fruit fruit = new Orange(); Console.WriteLine(fruit.GetColor()); fruit = new Apple(); Console.WriteLine(fruit.GetColor()); }
internal void Call() { Console.WriteLine("\nLiskov. object (fruit) is replace by its subtypes (apple and orange)"); Fruit fruit = new Orange(); Console.WriteLine(fruit.GetColor()); fruit = new Apple(); Console.WriteLine(fruit.GetColor()); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); Fruits apple = new Orange(); apple.GetColor(); apple = new Apple(); apple.GetColor(); }
static void Main(string[] args) { Apple apple = new Apple(); Orange orange = new Orange(); apple.GetColor("green"); orange.GetColor("red"); AppleAdapter appleAdapter = new AppleAdapter(orange); OrangeAdapter orangeAdapter = new OrangeAdapter(apple); appleAdapter.GetColor("blue"); orangeAdapter.GetColor("yellow"); }
public void GetToKnow() { Apple apple = new Apple(); apple.GetColor(); apple = new Orange(); apple.GetColor(); // After Fruit appleAfter = new OrangeAfter(); appleAfter.GetColor(); appleAfter = new AppleAfter(); appleAfter.GetColor(); }
static void Main(string[] args) { //The Dependency Inversion Principle (DIP) states that high-level modules/classes should not depend on low-level modules/classes. //Both should depend upon abstractions. Secondly, abstractions should not depend upon details. Details should depend upon abstractions. //dependency inversion principle var employee = new EmployeeBusinessLogic(); Console.WriteLine(JsonSerializer.Serialize(employee.GetEmployeeDetails(1))); //dependency inversion principle //liskov substitution principle : This principle states that, if S is a subtype of T, then objects of type T should be replaced with the objects of type S. // yerine koyma Apple apple = new Orange(); Console.WriteLine(apple.GetColor()); //after Fruit fruit = new Avocado(); Console.WriteLine(fruit.GetColor()); fruit = new Banana(); Console.WriteLine(fruit.GetColor()); //liskov substitution principle //open close principle var invoice = new Invoice(); Console.WriteLine(invoice.GetInvoiceDiscount(1000, InvoiceType.FinalInvoice)); Console.WriteLine(invoice.GetInvoiceDiscount(1000, InvoiceType.ProposedInvoice)); //after InvoiceOCP fInvoice = new FinalInvoice(); InvoiceOCP pInvoice = new ProposedInvoice(); InvoiceOCP rInvoice = new RecurringInvoice(); Console.WriteLine(fInvoice.GetInvoiceDiscount(100)); Console.WriteLine(pInvoice.GetInvoiceDiscount(100)); Console.WriteLine(rInvoice.GetInvoiceDiscount(100)); //open close principle Console.Read(); /* * * Single Responsibility : Sınıflarımızın iyi tanımlanmış tek bir sorumluluğu olmalı. * Open/Closed : Sınıflarımız değişikliğe kapalı ancak yeni davranışların eklenmesine açık olmalı. * Liskov Substitution(yerine koyma) : Kodumuzda herhangi bir değişiklik yapmaya gerek kalmadan türetilmiş sınıfları (sub class) türedikleri ata sınıfın (base class) yerine kullanabilmeliyiz. * Interface Segregation : Genel kullanım amaçlı tek bir kontrat yerine daha özelleşmiş birden çok kontrat oluşturmayı tercih etmeliyiz. * Dependency Inversion : Katmanlı mimarilerde üst seviye modüller alt seviyedeki modüllere doğruda bağımlı olmamalıdır. * */ // https://dotnettutorials.net/lesson/dependency-inversion-principle/ }
void Main() { Apple apple = new Orange(); Console.WriteLine(apple.GetColor()); }
static void Main(string[] args) { Apple apple = new Orange(); Console.WriteLine(apple.GetColor()); }