Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
321
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { abstract public class Duck { public FlyBehavior flyBehavior; public QuackBehavior quackBehavior; public void setFlyBehavior(FlyBehavior fb) { flyBehavior = fb; } public void setQuackBehavior(QuackBehavior qb) { quackBehavior = qb; } public void performQuack() { quackBehavior.quack(); } public void performFly() { flyBehavior.fly(); } public void swimme() { Console.WriteLine("Я плаваю"); } public abstract void display(); } public interface FlyBehavior { void fly(); } public interface QuackBehavior { void quack(); } public class Quack : QuackBehavior { public void quack() { Console.WriteLine("Крякаю"); } } public class Squeak : QuackBehavior { public void quack() { Console.WriteLine("Пищу"); } } public class MuteQuack : QuackBehavior { public void quack() { Console.WriteLine("Не разговариваю"); } } public class FlyWithWings : FlyBehavior { public void fly() { Console.WriteLine("Летаю на крыльях"); } } public class FlyNoWay : FlyBehavior { public void fly() { Console.WriteLine("Не умею летать"); } } public class DecoyDuck : Duck { public DecoyDuck() { quackBehavior = new MuteQuack(); flyBehavior = new FlyNoWay(); } public override void display() { Console.WriteLine("Приманка"); } } public class RubberDuck : Duck { public RubberDuck() { quackBehavior = new Squeak(); flyBehavior = new FlyNoWay(); } public override void display() { Console.WriteLine("Резиновая утка"); } } public class RedheadDuck : Duck { public RedheadDuck() { quackBehavior = new Quack(); flyBehavior = new FlyWithWings(); } public override void display() { Console.WriteLine("Нырок красноголовый"); } } public class MallardDuck : Duck { public MallardDuck() { quackBehavior = new Quack(); flyBehavior = new FlyWithWings(); } public override void display() { Console.WriteLine("Кряква"); } } public class Program { public static void Main(string[] args) { Duck DecoyDuck = new DecoyDuck(); DecoyDuck.performQuack(); DecoyDuck.performFly(); DecoyDuck.swimme(); Duck RubberDuck = new RubberDuck(); RubberDuck.performQuack(); RubberDuck.performFly(); RubberDuck.swimme(); Duck RedheadDuck = new RedheadDuck(); RedheadDuck.performQuack(); RedheadDuck.performFly(); RedheadDuck.swimme(); Duck mallardDuck = new MallardDuck(); mallardDuck.performQuack(); mallardDuck.performFly(); mallardDuck.swimme(); DecoyDuck.setQuackBehavior(new Squeak()); RubberDuck.setFlyBehavior(new FlyWithWings()); DecoyDuck.performQuack(); RubberDuck.performFly(); } } }
run
|
edit
|
history
|
help
0
printing * in pyramid shape
Non-User input - Random Controlled - Guessing Game
decimal to binary
an attempt at making a usable code thing (failed lol)
наименьшее общее кратное двух чисел a и b
bellman ford algo
SevenSevenSeven
RGEFCSZX
Simple Parallel.For example
show IP