java - Parent notification within array of objects -


so, i'm working on java program utilizes created class (we'll call "hair"). however, inside class, can have array of objects objects of class "hair". so, basically, looks this:

  • hair (level 0)
    • hair (level 1)
      • hair (level 2)
    • hair (level 1)

now, issue i'm having this: let's say, instance, change field in level 2. want level 1 notified, don't know how notify level 1. there way can have object talk object that's containing it? now, if using android, maybe use broadcast receiver, i'm not familiar in java or way directly talk "parent" hair level. suggestions?

for object talk parent must know it's parent. example:

class hair{   hair parent;   public hair(hair _parent){     parent = _parent;   }   public void notify(string data){     ... need   }   public void changehair(...){     ...     if(parent != null) {       parent.notify(...);     }   } 

if need more let me know.

edit: notify or down the object stack not in both directions can , cause problems without code handle not notifying notifier.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -