mardi 24 mai 2022

Identifying a Design pattern from a piece of C# code

I am trying to get a better understanding of the tech terms of design patterns, and in that case, im trying to guess the pattern from a piece of code.

I am a little stumpled with this one. What Pattern is this, and how do you know:

using System.Collections.Generic;

public abstract class Foo
{
    private readonly List<Bar> _list = new List<Bar>();

    public void Attach(Bar bar)
    {
        _list.Add(bar);
    }

    public void Detach(Bar bar)
    {
        _list.Remove(bar);
    }

    public void Notify()
    {
        foreach (var o in _list)
        {
            o.Update();
        }
    }
}

public abstract class Bar
{
    protected readonly Foo Foo;

    protected Bar(Foo foo)
    {
        Foo = foo;
    }

    public abstract void Update();
}

Any help or pointers would be appriciated :-)

Aucun commentaire:

Enregistrer un commentaire