// Define a one-to-many dependency between objects so that when one object changes state, all // its dependents are notified and updated automatically. public static void Main(string[] _) { var mohammad = new JobSeeker("Mohammad"); var ali = new JobSeeker("Ali"); var developer = new JobPosting(); developer.Subscribe(mohammad); developer.Subscribe(ali); developer.AddJob(new JobPost(".Net Developer")); developer.AddJob(new JobPost("Java Developer")); Console.ReadKey(); }
public static void Main(string[] args) { var soheil = new JobSeeker("Soheil"); var ali = new JobSeeker("Ali"); var jobPosting = new JobPosting(); jobPosting.Subscribe(soheil); jobPosting.Subscribe(ali); jobPosting.AddJob(new JobPost(".NET Developer")); jobPosting.AddJob(new JobPost("Java Developer")); Console.ReadKey(); }
static void Main(string[] args) { var jobSeeker = new JobSeeker("Martin"); var jobSeekers = new List <IObserver> { new JobSeeker("Tim"), new JobSeeker("Angela"), new JobSeeker("Jeff"), }; var headHunter = new HeadHunter(); headHunter.RegisterObserver(jobSeeker); headHunter.RegisterObservers(jobSeekers); headHunter.AddJob("Google job"); headHunter.RemoveObserver(jobSeeker); headHunter.AddJob("Microsoft job"); }
static void Main() { // create subscribers var johnDoe = new JobSeeker("John Doe"); var janeDoe = new JobSeeker("Jane Doe"); // create publisher and attach subscribers var jobPostings = new JobPostings(); var johnDoeSubscription = jobPostings.Subscribe(johnDoe); jobPostings.Subscribe(janeDoe); // add a new job and see if subscribers get notified jobPostings.AddJob(new JobPost("Software Engineer")); // unsubscribe, notify Jane about DT role johnDoeSubscription.Dispose(); jobPostings.AddJob(new JobPost("Design Technologist")); Console.ReadLine(); }