Adapterアダプタモード

1208 ワード


/**
 * Adapter <br>
 *  
 */
public class Printer {
	/**
	 *  , , 
	 * @param array
	 */
	public void printIntArray(int[] array)
	{
		if(array != null)
		{
			for(int i=0;i<array.length;i++)
			{
				System.out.print(array[i] + " ");
			}
			System.out.println();
		}
	}
}

/**
 *  , 
 */
public class PrintAdapter extends Printer implements ISortNumber 
{
	private ISortNumber mySort;
	public PrintAdapter(ISortNumber sort)
	{
		super();
		this.mySort = sort;
	}
	
	public int[] sortASC(int[] intArray) {
		if(this.mySort!=null)
		{
			return this.mySort.sortASC(intArray);
		}
		else
		{
			return null;
		}
	}
	
	public static void main(String[] args)
	{
		int[] array = new int[]{7,9,4,6,2,-1,12};
		PrintAdapter adapter = new PrintAdapter(Factory.getOrderNumber(Factory.BUBBLE_SORT));
		adapter.printIntArray(adapter.sortASC(array));
	}
	
}