Wrap the child's waking situation into an event class
Test.java
Class Wakenupevent{private Long time;private string location;private child source;public wakenupevent (long time, string l Ocation, child source) {super (); this.time = Time;this.location = Location;this.source = Source;} Public long GetTime () {return time;} public void SetTime (long time) {this.time = time;} Public String getLocation () {return location;} public void setlocation (String location) {this.location = location;} Public child GetSource () {return source;} public void SetSource (child source) {This.source = source;}} Class Child implements Runnable {private dad dad;public Child (Dad dad) {This.dad = Dad;} public void WakeUp () {Dad.actiontowakenup (New Wakenupevent (System.currenttimemillis (), "bed", this)); @Overridepublic void Run () {try {thread.sleep;} catch (Exception e) {e.printstacktrace ();} WakeUp ();}} Class Dad {public void Actiontowakenup (Wakenupevent e) {System.out.println (E.gettime ()); System.out.println (E.getlocation ()); System.out.println (E.getsource ()); System.out.println ("Fedd the Child ");}} public class Test {public static void main (string[] args) {Dad d = new Dad (); Child C = new Child (d); new Thread (c). Start ();}}
Operation Result:
Java OOD Encapsulation Event