9
Database insert(record r): boolean find(key k): Record 1 Record getkey(): Key * Record Key Database.? Key equals(key y): boolean
Database insert(record r): boolean find(key k): Record * Database OK 1 Record getkey(): Key Key equals(key y): boolean Record1 Key id; String name; getkey(): Key; Record2 Key code; String title; boolean is_borrowed; getkey(): Key; Key1 private int no; equals(key1 y): Key2 string category; private int no; equals(key2 y):
Record1 Key id; String name; getkey(): Key; Java (interface).. Record getkey(): Key Record2 Key code; String title; boolean is_borrowed; getkey(): Key; Java Record.,.
interface < > { < >,,,. interface Key { boolean equals(key y); interface Record { Key getkey();
.,, new.., Key k;, void method (Key k) {..., Key getkey() {...
implements < >. class IntegerKey implements Key { private int key; public IntegerKey(int i) { key = i; public int getint() { return key; Key equals boolean equals(key k) { return key == ((IntegerKey)k).getInt();
. class CodeKey implements Key { private String category; private int code; public CodeKey(String s, int i) { category=s; code=i; public String getcategory() { return category; public int getcode() { return code; Key equals boolean equals(key k) { CodeKey ck = (CodeKey) k; return category.equals(ck.getcategory()) && code == ck.getint();
IntegerKey, CodeKey Key. class findlocationdatabase {... private int findlocation(key k) { for (int i=0; i<base.length; i++) if(base[i]=null && k.equals(base[i].getkey())) return i; return NOT_FOUND;...
,,,,??. : * *
: + +
CSE216 프로그램 설계 방법론 인터페이스 구현: 요구조건만 만족 인공지능 로봇: * 대화 * 장애물을 피하면서 이동 로봇 제작설명서 로봇 제작설명서 로봇 제작설명서 인터페이스 로봇 제작설명서 한양대학교 ERICA 컴퓨터공학과
vs. class B extends A class B implements A A x = new B();,.
,.......
public interface RoomBehaviour { public boolean enter(playerbehaviour p); public void exit(playerbehaviour p); public PlayerBehaviour occupantof(); public interface PlayerBehaviour { public String speak(); public boolean explore(roombehaviour r);
public class BasicRoom implements RoomBehaviour { private PlayerBehaviour occupant; private String rooms_name; private String secret_word; public BasicRoom(String name, String password) { occupant = null; rooms_name = name; secret_word = password; public boolean enter(playerbehaviour p) { boolean result = false; if(occupant == null && secret_word.equals(p.speak())) { occupant = p; result = true; return result; public void exit(playerbehaviour p) { if(occupant == p) occupant = null; public PlayerBehaviour occupantof() { return occupant;
public class Explorer implements PlayerBehaviour { private String name, secret_word; private RoomBehaviour where_i_am; public Explorer(String n, String w) { name = n; secret_word = w; where_i_am = null; public String speak() { return secret_word; public void exitroom() { if(where_i_am = null) { where_i_am.exit(this); where_i_am = null; public boolean explore(roombehaviour r) { if(where_i_am = null) exitroom(); boolean went_inside = r.enter(this); if(went_inside) where_i_am = r; return went_inside; public RoomBehaviour locationof() { return where_i_am;
RoomBehaviour[] ground_floor = new RoomBehaviour[4]; ground_floor[0] = new BasicRoom("kitchen", "pasta"); ground_floor[3] = new BasicRoom("lounge", "swordfish"); Explorer harpo = new Explorer("Harpo Marx", "swordfish"); Explorer chico = new Explorer("Chico Marx", "tomato"); boolean success = harpo.explore(ground_floor[3]);
.. public interface TreasureProperty { public String contentsof(); public interface TreasuryRoomBehaviour { public boolean enter(playerbehaviour p); public void exit(playerbehaviour p); public TreasureProperty yieldtreasure(playerbehaviour p); public PlayerBehaviour occupantof();
: public interface RoomBehaviour { public boolean enter(playerbehaviour p); public void exit(playerbehaviour p); public PlayerBehaviour occupantof(); public interface Treasury { public TreasureProperty yieldtreasure(playerbehaviour p); public class VaultRoom implements Treasury, RoomBehaviour { //...
: public interface RoomBehaviour { public boolean enter(playerbehaviour p); public void exit(playerbehaviour p); public PlayerBehaviour occupantof(); public interface TreasuryRoomBehaviour extends RoomBehaviour { public TreasureProperty yieldtreasure(playerbehaviour p); public class VaultRoom implements TreasuryRoomBehaviour { //...
interface RoomBehaviour interface Treasury interface RoomBehaviour interface TreasuryRoomBehaviour class VaultRoom class VaultRoom
,? interface Treasury interface RoomBehaviour interface TreasuryRoomBehaviour public interface TreasuryRoomBehaviour extends Treasury, RoomBehaviour { public class VaultRoom implements TreasuryRoomBehaviour { //... class VaultRoom
? interface Treasury class Golden interface RoomBehaviour class BasicRoom (multiple inheritance). Java. class VaultRoom
,
,. m(b x) {... m(c x) {... m(d x) {...... m(a x) {..., B, C, D A, A
(Subtype)., < < < < <,.
. ===> ==>. ==> ==>
Java class B extends A class B implements A B < A? a.method(); b.method(); b.method(); a.method();
A x = y; y B A B OK. void m(a x) m(y) y x., y B A B OK.
? B < A B[]?? A[] A[] arr = new B[]; a[0] = new A(); (X) B[] > A[], Java B[] < A[]
IntegerKey, CodeKey Key. class findlocationdatabase {... private int findlocation(key k) { for (int i=0; i<base.length; i++) if(base[i]=null && k.equals(base[i].getkey())) return i; return NOT_FOUND;...
interface Key {. boolean equals(key y); class IntegerKey implements Key { private int key; public IntegerKey(int i) { key = i; public int getint() { return key; boolean equals(key k) { return key == ((IntegerKey)k).getInt();... boolean equals(integerkey k)?
Key interface Key { boolean equals(key y); class IntegerKey implements Key {... boolean equals(key k) {... equals Key. return key == ((IntegerKey)k).getInt(); Key k IntegerKey k Key k Key y Key,, IntegerKey IntegerKey y, CodeKey CodeKey y.
. boolean equals(key k) {... (IntegerKey) k... IntegerKey ik; CodeKey ck; ik.equals(ck);? if(k instanceof IntegerKey) {... (IntegerKey) k... else {
, IntegerKey.equals interface Key { boolean equals(key y); class IntegerKey implements Key {... boolean equals(key k) { if(k instanceof IntegerKey) return key == ((IntegerKey)k).getInt(); else return false;...
(Generic) Key, Key equals. Key<T> T equals. Key<T extends Key<T>> Key<T> T equals. class IntegerKey implements Key<IntegerKey> {... IntegerKey.
, IntegerKey.equals interface Key <T extends Key<T>> { boolean equals(t y); class IntegerKey implements Key <IntegerKey> {... boolean equals(integerkey k) { return key == k.getint();
Database public interface Key <T extends Key<T>>{ boolean equals(t k); public interface Record <K extends Key<K>>{ K getkey(); public class Database <K extends Key<K>, R extends Record<K>>{ private R[] base;... public Database (int initial_size) {... private int findlocation(k k) {... private int findempty() {... public R find(k k) {... public boolean delete(k k) {... public boolean insert(r r) {... : new R[10] (R[]) new Record[10]
(Abstract Class), ==> ==>
, class Card class CardDeck class Dealer,. interface CardPlayerBehaviour interface public interface CardPlayerBehaviour { public boolean wantsacard(); public void receivecard(card c);
,..,?.. " " CardPlayer.
public abstract class CardPlayer implements CardPlayerBehaviour { private Card[] my_hand; private int card_count; public CardPlayer(int max_cards) { my_hand = new Card[max_cards]; card_count = 0; public abstract boolean wantsacard(); public void receivecard(card c) { my_hand[card_count] = c; card_count = card_count + 1;
import javax.swing.*; public class HumanPlayer extends CardPlayer { public HumanPlayer(int max_cards) { super(max_cards); public boolean wantsacard() { String response = JOptionPane.showInputDialog ("Do you want another card (Y or N)?"); return response.equals("y");. CardPlayer(). super CardPlayer(max_cards).
public class ComputerPlayer extends CardPlayer { public ComputerPlayer(int max_cards) { super(max_cards); public boolean wantsacard() { int sum = 0; for(int i=0; i<card_count; i++) sum += my_hand[i].getcount(); return sum < 15;
Dealer CardPlayerBehavior wantsacard(): boolean receivecard(card c) CardPlayer wantsacard(): boolean receivecard(card c) HumanPlayer wantsacard(): boolean ComputerPlayer wantsacard(): boolean
public abstract class Animal { // public abstract class WarmBlooded extends Animal { // public abstract class Equine extends WarmBlooded { // public class Horse extends Equine { //
Form Point Line Straight Jagged Curved Shape Curved Circle Ellipse Polygon Triangle Rectangle
(Framework)., GraphicsWindow setsize, setbackground, setvisible paint paint Java.
vs,,.,.. Interfaces list behaviours abstract classes list codings
OK,.,?. Java Object. Object.,.
Object Object[] a = new Object[10]; 10 a[0] = new Integer(10); a[1] = "abc";, a[1]? int arraysize(object[] a) { return a.length;...arraysize(new int[10]);...arraysize(new String[5]);, a[1]?
. Object[] a = new Object[10]; a[0] = new Integer(25); System.out.println(a[0].getInteger() / 10); //. a[0] Object // getinteger. System.out.println(((Integer)a[0]).getInteger() / 10); //. System.out.println(a[0]); //.? Object tostring() //.
(Package),., java.util, java.awt, javax.swing import.,.
Java. : ( ) ( ) :,. Java,,. Object.