Skip to content

Instantly share code, notes, and snippets.

View hsynkrcf's full-sized avatar
🎯
Focusing

Hüseyin Karacif hsynkrcf

🎯
Focusing
View GitHub Profile
@hsynkrcf
hsynkrcf / Phone.cs
Created November 10, 2022 00:27
YES OCP
public abstract class Phone
{
public abstract void Make();
}
public class Iphone : Phone
{
public override void Make()
{
Console.WriteLine("Iphone Created\n");
@hsynkrcf
hsynkrcf / Program.cs
Last active November 9, 2022 22:56
OCP
class Program
{
static void Main(string[] args)
{
PhoneFactory pf1 = new PhoneFactory();
pf1.MakePhone(new Iphone());
PhoneFactory pf2 = new PhoneFactory();
pf2.MakePhone(new Samsung());
Console.ReadLine();
}
public class PhoneFactory
{
public void MakePhone(Phone phone)
{
switch (phone.Type)
{
case PhoneType.Iphone:
MakeIphone((Iphone)phone);
break;
case PhoneType.Samsung:
@hsynkrcf
hsynkrcf / Phone.cs
Created November 9, 2022 22:22
OCP
public class Phone
{
public PhoneType Type { get; set; }
}
public enum PhoneType
{
Iphone,
Samsung
}
public class Iphone : Phone