Skip to content

Instantly share code, notes, and snippets.

View arjunsk's full-sized avatar
:octocat:
Learning!

Arjun Sunil Kumar arjunsk

:octocat:
Learning!
View GitHub Profile
package products;
public interface IPrinter {
public void print(String data);
public boolean stop();
}
package products;
public class InkjetPrinter implements IPrinter {
@Override
public void print(String data) {
System.out.println("Inkjet Actions performed on "+data);
}
@Override
package products;
public class DotMatrixPrinter implements IPrinter {
@Override
public void print(String data) {
System.out.println("DotMatrix Actions performed on "+data);
}
@Override
package products;
public class LaserPrinter implements IPrinter {
@Override
public void print(String data) {
System.out.println("Laser Actions performed on "+data);
}
@Override
package solver;
import products.DotMatrixPrinter;
import products.IPrinter;
import products.InkjetPrinter;
import products.LaserPrinter;
public class PrinterFactory {
public static IPrinter createPrinterInstance(String type){
package main;
import products.IPrinter;
/*
* Somewhat similar to Strategy, but instead of choosing algorithms, we select sub-class
* https://www.quora.com/What-is-factory-pattern-design
* https://www.quora.com/How-are-design-patterns-implemented-in-real-life
*
*/
package noun;
import algorithms.LargerSorter;
import algorithms.MediumSorter;
import algorithms.SmallSorter;
import algorithms.ISorter;
public class BinarySearch {
package algorithms;
public interface ISorter {
public int[] sort(int array[]);
}
package algorithms;
import java.util.Arrays;
public class SmallSorter implements ISorter{
@Override
public int[] sort(int arr[]) {
// Implement bubble sort or similar
System.out.println("Small sort used.");
package algorithms;
import java.util.Arrays;
public class MediumSorter implements ISorter{
@Override
public int[] sort(int arr[]) {
// Implement merge sort or similar.
System.out.println("Medium sort used.");