JAVA Programming

[48] 인터페이스 요소들

꾸준히개발하자 2020. 7. 17. 10:01

 

인터페이스 Queue 에다가 메소드를 명세해 놓는다.  

package scheduler2;

public interface Queue {
	
	void enQueue(String title);
	String deQueue();
	int getSize();
	void info();
}

 

Shelf 클래스에  구현해 놓는다. 

package scheduler2;

import java.util.ArrayList;

public class Shelf {
	
	protected ArrayList<String> shelf;
	
	public Shelf() {
		
		shelf = new ArrayList<String>();
	}
	
	public ArrayList<String> getShelf() {
		return shelf;
	}
	
	public int getCount() {
		return shelf.size();
	}
	
	public void info() {
		
		for(String str : shelf) {
			System.out.println(str);
		}
	}
}

 

 

BookShelf 는   Shelf 구현한 클래스를 상속받고  Queue 인터페이스를 상속받는다

package scheduler2;

public class BookShelf extends Shelf implements Queue {

	@Override
	public void enQueue(String title) { // 문자를 집어 넣는다
		
		shelf.add(title);
	}

	@Override
	public String deQueue() { // 문자를 빼낸다.
		return shelf.remove(0);
	}

	@Override
	public int getSize() {
		return getCount();
	}
	

}

 

 

구현 클래스

 

package scheduler2;

public class BookShelfTest {
	
	public static void main(String[] args) {
	
		Queue queue = new BookShelf();
		
		queue.enQueue("태백산맥");
		queue.enQueue("태백산맥2");
		queue.enQueue("태백산맥3");
		
		System.out.println(queue.deQueue() + " 빼낸거 "); 

		System.out.println("=========남은거=======");
		queue.enQueue("태백산맥4");
		queue.info();
	}
}

 

출력 결과