Thursday, December 13, 2012

Design Patterns : Abstract Factory Pattern 2

The reader might have already observed that we need a component interface to define the minimum three components of the Computer factories. The below listing provides the Component interface

package com.company.self.study.core.java;

/**
*
* Abstract Factory Pattern Example
*
* @author administrator
*
*/
public interface Component {

}


Next we start on the designing the components which are being used by the independent factories of the Computer to churn the concrete implementations

 The Processor Core first

package com.company.self.study.core.java;

/**
*
*
* Abstract Factory Pattern Example
*
* @author administrator
*
*/
public class ProcessorCore implements Component {

private String core;



public ProcessorCore(String core) {
super();
this.core = core;
}

public String getCore() {
return core;
}
public void setCore(String core) {
this.core = core;
}

public String toString() {
return core;
}
}


 Next Memory


package com.company.self.study.core.java;

/**
*
* Abstract Factory Pattern Example
*
*
* @author administrator
*
*/
public class Memory implements Component {

private String size;

public Memory(String size) {
super();
this.size = size;
}

public String getSize() {
return size;
}

public void setSize(String size) {
this.size = size;
}


public String toString() {
return size;
}
}


 Finally HardDisk

package com.company.self.study.core.java;

/**
*
* Abstract Factory Pattern Example
*
*
*
* @author administrator
*
*/
public class HardDisk implements Component {

private String volume;



public HardDisk(String volume) {
super();
this.volume = volume;
}

public String getVolume() {
return volume;
}

public void setVolume(String volume) {
this.volume = volume;
}

public String toString() {
return volume;
}
}


 On next post we would terminate the discussion by listing the actual Abstract Factory and the Tester. Of course with the Runner and the Output listed too.

No comments: