Skip to content

Instantly share code, notes, and snippets.

View ssukhpinder's full-sized avatar
🏠
Working from home

Sukhpinder Singh ssukhpinder

🏠
Working from home
View GitHub Profile
public class Sukhpinder : ICelebrityInstagram
{
private readonly List<IFollower> _posts = new List<IFollower>();
private string _post;
public string FullName => "Sukhpinder Singh";
public string Post {
get { return _post; }
set
{
public class Follower : IFollower
{
public void Update(ICelebrityInstagram celebrityInstagram)
{
Console.WriteLine($"Follower notified. Post of {celebrityInstagram.FullName}: " +
$"{celebrityInstagram.Post}");
}
}
static void Main(string[] args)
{
IVehicleAggregate car = new Vehicles.Car();
IVehicleAggregate motercycle = new Vehicles.Motercycle();
IVehicleIterator carIterator = car.CreateIterator();
IVehicleIterator motercycleIterator = motercycle.CreateIterator();
PrintVehicles(carIterator);
PrintVehicles(motercycleIterator);
public class Motercycle : IVehicleAggregate
{
private string[] _motercycles;
public Motercycle()
{
_motercycles = new[] { "Bike 1", "Bike 2", "Bike 3" };
}
public IVehicleIterator CreateIterator()
{
public class Car : IVehicleAggregate
{
private List<string> _cars;
public Car()
{
_cars = new List<string> { "Car 1", "Car 2", "Car 3" };
}
public IVehicleIterator CreateIterator()
{
public class MotercycleIterator : IVehicleIterator
{
private string[] _motercylces;
private int _current;
public MotercycleIterator(string[] motercylces)
{
_motercylces = motercylces;
_current = 0;
}
public string Current()
public class CarIterator : IVehicleIterator
{
private List<string> _cars;
private int _current;
public CarIterator(List<string> cars)
{
_cars = cars;
_current = 0;
}
public string Current()
static void Main(string[] args)
{
Car car = new SmallCar();
Console.WriteLine($"Price of car {car.GetName()} : " + car.CarPrice());
var car1 = new Sunroof(car);
Console.WriteLine($"Price of car {car1.GetName()} : " + car1.CarPrice());
var car2 = new AdvanceMusic(car);
Console.WriteLine($"Price of car {car2.GetName()} : " + car2.CarPrice());
public class Sunroof : CarDecorator
{
public Sunroof(Car car) : base(car)
{
}
public override int CarPrice() => _car.CarPrice() + 2000;
public override string GetName() => "Alto Lxi with Sunroof";
}
public class AdvanceMusic : CarDecorator
{
public AdvanceMusic(Car car) : base(car)
{
}
public override int CarPrice() => _car.CarPrice() + 3000;
public override string GetName()=> "Alto Lxi with advance music system";
}