Click here to Skip to main content
15,569,858 members

Comments by Dirk Bahle (Top 37 by date)

Dirk Bahle 8-Jan-19 10:11am View    
I only meant the INotifyPropertyChanged is necessary if you want to display the count in the UI. But thats just guess work since the provided code sample does not show what was tried so far ...
Dirk Bahle 23-Nov-18 7:50am View    
Not sure whaz your problem is - woud you care to explain your problem?
Dirk Bahle 28-Sep-18 7:28am View    
I have read Ben's article the other day and thought his pattern is quit interesting since I have run into similar problems. I had no time to try it out for myself but maybe there is something helpful here:
https://www.codeproject.com/Articles/1220093/A-Robust-Solution-for-FileSystemWatcher-Firing-Eve
Dirk Bahle 28-Sep-18 7:23am View    
thanx - really funny this random downvoting...
Dirk Bahle 28-Sep-18 7:19am View    
Thats a great start but you can still run into problems once you are looking at a large code base - what you want to do in this case is to seal your classes away into a library project and then have only the factory method and the interface definition be visible to the outside world. Copy the code below into a library project, reference the library in the startup project and use the following line to create for example a Horse: ICreature hores = Factory.CreateHorse()

    internal abstract class Creature
    {
        public virtual void Walk()
        {

        }

        public virtual void Run()
        {

        }

        public virtual void Swim()
        {

        }
    }

    public interface ICreature
    {
        void Walk();

        void Run();

        void Swim();
    }

    internal class Tiger : Creature, ICreature
    {

    }

    internal class Horse : Creature, ICreature
    {
        public override void Walk()
        {
            throw new Exception("Can walk");
        }
    }

    internal class Fish : Creature, ICreature
    {
        public override void Walk()
        {
            throw new Exception("Can walk");
        }

        public override void Run()
        {
            throw new Exception("Can Run");
        }
    }

    internal class Tortoise : Creature, ICreature
    {
        public override void Run()
        {
            throw new Exception("Can Run");
        }
    }

    public static class Factory
    {
        public static ICreature CreateTiger()
        {
            return new Tiger();
        }

        public static ICreature CreateHorse()
        {
            return new Horse();
        }

        public static ICreature CreateFish()
        {
            return new Fish();
        }

        public static ICreature CreateTortoise()
        {
            return new Tortoise();
        }
    }