Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- using System.Threading;
- using System.Linq;
- class Program
- {
- static void Main(string[] args)
- {
- Car auto = new Car(4, "Volvo", new PetrolMove());
- auto.Move();
- auto.Movable = new ElectricMove();
- auto.Move();
- Console.ReadLine();
- }
- }
- interface IMovable
- {
- void Move();
- }
- class PetrolMove: IMovable
- {
- public void Move()
- {
- Console.WriteLine("Передвижение на бензине");
- }
- }
- class ElectricMove: IMovable
- {
- public void Move()
- {
- Console.WriteLine("Передвижение на электричестве");
- }
- }
- class Car
- {
- protected int passengers {get;set;}
- protected string model {get;set;}
- public IMovable Movable {private get;set;}
- public Car(int num, string model, IMovable mov)
- {
- this.passengers = num;
- this.model = model;
- this.Movable = mov;
- }
- public void Move()
- {
- Movable.Move();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement