mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
zanninso
1da05b5964
|
1 year ago | |
---|---|---|
.. | ||
README.md | 1 year ago |
README.md
Singleton
Instructions
In this quest, we will implement some design patterns.
For first, we will implement the singleton pattern.
classDiagram
class Excalibur{
-String name
-Excalibur INSTANCE$
-Excalibur(String name)
+getName() String
+getInstance()$ Excalibur
}
Excalibur <-- Excalibur
Here is the matching class diagram. Create the matching class in the matching file.
When calling the getInstance method, an instance of Excalibur with name "Sword"
Usage
Here is a possible ExerciseRunner.java to test your function :
public class ExerciseRunner {
public static void main(String[] args) {
System.out.println(Excalibur.getInstance().getName());
}
}
and its output :
$ javac *.java -d build
$ java -cp build ExerciseRunner
Sword
$