forked from ramram43210/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.java
More file actions
58 lines (43 loc) · 1.88 KB
/
Copy pathClient.java
File metadata and controls
58 lines (43 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
public class Client
{
public static void main( String[] args )
{
Animal animal = null;
AnimalFactory animalFactory = null;
String speakSound = null;
// Get Factory object by passing the factory type
animalFactory = AnimalFactory.getAnimalFacory("sea");
System.out.println("Animal Factory type : " + animalFactory.getClass().getName());
System.out.println();
// Get Animal object by passing the animal type
animal = animalFactory.getAnimal("shark");
System.out.println("Animal Type : "+animal.getClass().getName());
speakSound = animal.speak();
System.out.println("shark speak : "+speakSound);
System.out.println();
animal = animalFactory.getAnimal("octopus");
System.out.println("Animal Type : "+animal.getClass().getName());
speakSound = animal.speak();
System.out.println("octopus speak : "+speakSound);
System.out.println("---------------------------------------------------------");
// Get Factory by passing the factory type
animalFactory = AnimalFactory.getAnimalFacory("land");
System.out.println("Animal Factory type : " + animalFactory.getClass().getName());
System.out.println();
// Get Animal object by passing the animal type
animal = animalFactory.getAnimal("dog");
System.out.println("Animal Type : "+animal.getClass().getName());
speakSound = animal.speak();
System.out.println("dog speak : "+speakSound);
System.out.println();
animal = animalFactory.getAnimal("cat");
System.out.println("Animal Type : "+animal.getClass().getName());
speakSound = animal.speak();
System.out.println("cat speak : "+speakSound);
System.out.println();
animal = animalFactory.getAnimal("lion");
System.out.println("Animal Type : "+animal.getClass().getName());
speakSound = animal.speak();
System.out.println("lion speak : "+speakSound);
}
}