Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ConsoleApplication4983
- {
- public class MyClass
- {
- static void Main()
- {
- var c = new MyClass();
- c.DoSomething(new Sequential());
- c.DoSomething(new Random());
- }
- public void DoSomething(ProcessingMethod method)
- {
- if (method is Sequential)
- {
- // do something sequential
- }
- else if (method is Random)
- {
- // do something random
- }
- }
- }
- public class ProcessingMethod {}
- public class Sequential : ProcessingMethod {}
- public class Random : ProcessingMethod {}
- }
- using System;
- namespace ConsoleApplication4983
- {
- public class MyClass
- {
- static void Main()
- {
- var c = new MyClass();
- c.DoSomething(new Sequential());
- c.DoSomething(new Random());
- }
- public void DoSomething(ProcessingMethod method)
- {
- method.Foo();
- }
- }
- public class ProcessingMethod
- {
- public virtual void Foo() { }
- }
- public class Sequential : ProcessingMethod
- {
- public override void Foo() { }
- }
- public class Random : ProcessingMethod
- {
- public override void Foo() { }
- }
- }
- public interface IProcessingMethod
- {
- void Process();
- }
- public class SequentialProcess : IProcessingMethod
- {
- public void Process( IProcessable obj )
- {
- do something sequentially with the obj
- }
- }
- public class ParallelProcess : IProcessingMethod
- {
- public void Process( IProcessable obj )
- {
- do something in parallel with the obj
- }
- }
- public interface IProcessable
- {
- void Process( IProcessingMethod method );
- }
- public class MyClass : IProcessable
- {
- public void Process( IProcessingMethod method )
- {
- method.Process( this );
- }
- }
- ...
- var obj = new MyClass();
- obj.Process( new SequentialProcess() );
- public void DoSomething(ProcessingMethod method) {
- method.DoSomething();
- }
- public void DoSomething(ProcessingMethod method)
- {
- method.Process();
- }
- public abstract class ProcessingMethod
- {
- public abstract void Process();
- }
- public class Sequental : ProcessingMethod
- {
- public override void Process()
- {
- // do something sequential
- }
- }
- public class Random : ProcessingMethod
- {
- public override void Process()
- {
- // do something random
- }
- }
- public class Parallel : ProcessingMethod{}
- namespace ConsoleApplication4983
- {
- public class MyClass
- {
- static void Main()
- {
- var c = new MyClass();
- c.DoSomething(ProcessingMethod.Sequential);
- c.DoSomething(ProcessingMethod.Random);
- }
- public void DoSomething(ProcessingMethod method)
- {
- if (method == ProcessingMethod.Sequential)
- {
- // do something sequential
- }
- else if (method == ProcessingMethod.Random)
- {
- // do something random
- }
- }
- }
- public enum ProcessingMethod
- {
- Sequential,
- Random
- }
- }
Add Comment
Please, Sign In to add comment