Skip to content

Commit 01a8c2b

Browse files
initial commit for Factory
1 parent eea6225 commit 01a8c2b

19 files changed

Lines changed: 191 additions & 2 deletions

File tree

Factory/.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.gradle
2+
/build/
3+
!gradle/wrapper/gradle-wrapper.jar
4+
5+
### STS ###
6+
.apt_generated
7+
.classpath
8+
.factorypath
9+
.project
10+
.settings
11+
.springBeans
12+
.sts4-cache
13+
14+
### IntelliJ IDEA ###
15+
.idea
16+
*.iws
17+
*.iml
18+
*.ipr
19+
/out/
20+
21+
### NetBeans ###
22+
/nbproject/private/
23+
/nbbuild/
24+
/dist/
25+
/nbdist/
26+
/.nb-gradle/
769 Bytes
Binary file not shown.
Binary file not shown.
923 Bytes
Binary file not shown.
935 Bytes
Binary file not shown.
Binary file not shown.

Factory/build.gradle

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/********** Applying Plugin *************/
2+
apply plugin: 'java'
3+
apply plugin: 'eclipse'
4+
5+
/********** buildscript *************/
6+
buildscript {
7+
ext {
8+
version = '2.0.1.RELEASE'
9+
}
10+
repositories {
11+
mavenCentral()
12+
}
13+
dependencies {
14+
15+
}
16+
}
17+
18+
repositories {
19+
mavenCentral()
20+
}
21+
22+
sourceCompatibility = 1.7
23+
group = 'com.java.design.pattern'
24+
version = '0.0.1-SNAPSHOT'
25+
26+
println "Starting Building Project:"+project.name
27+
28+
jar
29+
{
30+
baseName=project.name
31+
32+
}
33+
34+
35+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.java.design.pattern.factory;
2+
3+
public abstract class Computer {
4+
5+
public abstract String getComputerType();
6+
public abstract String getRAM();
7+
public abstract String getHDD();
8+
public abstract String getCPU();
9+
10+
@Override
11+
public String toString()
12+
{
13+
return "Computer Type:"+this.getComputerType()+",RAM:"+this.getRAM()+",HDD:"+this.getHDD()+",CPU:"+this.getCPU();
14+
15+
}
16+
17+
18+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.java.design.pattern.factory;
2+
3+
public class ComputerFactory {
4+
5+
public static Computer getComputer(String compType, String ram, String hdd, String cpu){
6+
if("PC".equalsIgnoreCase(compType))
7+
return new PC(compType,ram, hdd, cpu);
8+
else if("Server".equalsIgnoreCase(compType))
9+
return new Server(compType,ram, hdd, cpu);
10+
11+
return null;
12+
}
13+
14+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.java.design.pattern.factory;
2+
3+
public class PC extends Computer {
4+
5+
private String Comptype;
6+
private String RAM;
7+
private String HDD;
8+
private String CPU;
9+
10+
public PC(String compType,String RAM,String HDD,String CPU)
11+
{
12+
this.Comptype=compType;
13+
this.RAM=RAM;
14+
this.HDD=HDD;
15+
this.CPU=CPU;
16+
17+
}
18+
19+
@Override
20+
public String getRAM() {
21+
// TODO Auto-generated method stub
22+
return RAM;
23+
}
24+
25+
@Override
26+
public String getHDD() {
27+
// TODO Auto-generated method stub
28+
return HDD;
29+
}
30+
31+
@Override
32+
public String getCPU() {
33+
// TODO Auto-generated method stub
34+
return CPU;
35+
}
36+
37+
@Override
38+
public String getComputerType() {
39+
// TODO Auto-generated method stub
40+
return Comptype;
41+
}
42+
43+
}

0 commit comments

Comments
 (0)