浏览代码

Utilisation singleton

Arthur Brandao 6 年之前
父节点
当前提交
fdb6b4d1f8
共有 1 个文件被更改,包括 6 次插入1 次删除
  1. 6 1
      src/migl/lisp/LispFactory.java

+ 6 - 1
src/migl/lisp/LispFactory.java

@@ -7,6 +7,8 @@ package migl.lisp;
  *
  *
  */
  */
 public class LispFactory {
 public class LispFactory {
+	
+	private static Lisp interpreter;
 
 
     private LispFactory() {
     private LispFactory() {
         // do nothing
         // do nothing
@@ -18,6 +20,9 @@ public class LispFactory {
      * @return a new lisp interpreter.
      * @return a new lisp interpreter.
      */
      */
     public static Lisp makeIntepreter() {
     public static Lisp makeIntepreter() {
-        return new LispImpl();
+    	if(interpreter == null) {
+    		interpreter = new LispImpl();
+    	}
+        return interpreter;
     }
     }
 }
 }