2015-07-24 11:32:22 +03:00
|
|
|
package com.iluwatar.lazy.loading;
|
2015-04-10 20:24:16 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2015-11-01 21:29:13 -05:00
|
|
|
* Simple implementation of the lazy loading idiom. However, this is not thread safe.
|
2015-04-10 20:24:16 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class HolderNaive {
|
|
|
|
|
2015-11-01 21:29:13 -05:00
|
|
|
private Heavy heavy;
|
|
|
|
|
2015-12-25 23:49:28 +02:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
2015-11-01 21:29:13 -05:00
|
|
|
public HolderNaive() {
|
|
|
|
System.out.println("HolderNaive created");
|
|
|
|
}
|
|
|
|
|
2015-12-25 23:49:28 +02:00
|
|
|
/**
|
|
|
|
* Get heavy object
|
|
|
|
*/
|
2015-11-01 21:29:13 -05:00
|
|
|
public Heavy getHeavy() {
|
|
|
|
if (heavy == null) {
|
|
|
|
heavy = new Heavy();
|
|
|
|
}
|
|
|
|
return heavy;
|
|
|
|
}
|
2015-04-10 20:24:16 +03:00
|
|
|
}
|