using System;
using Patterns_And_Principles.Patterns.The_Observer_Pattern.WithoutEvent.Script._01_BasicExample.Interface;
using UnityEngine;

namespace Patterns_And_Principles.Patterns.The_Observer_Pattern.WithoutEvent.Script._01_BasicExample
{
    public class Observer : MonoBehaviour, IObserver
    {
        private Subject _subject;

        private void OnEnable()
        {
            _subject.Attach(this);
        }

        private void OnDisable()
        {
            _subject.Detach(this);
        }

        private void Awake()
        {
            _subject = FindObjectOfType<Subject>();
        }

        public void Notify(ISubject subject)
        {
            if (subject != null)
            {
                Debug.Log("Observer Notify");
            }
        }
    }
}