1. 내가설계한 template method pattern 예제

제목 : 프로그래밍

template method pattern이란 알고리즘의 뼈대를 만들어 전체적인 레이아웃을 통일 시키지만 상속받은 클래스로 하여금 어느정도 유연성을 주도록하는 패턴이다.

추상 메소드와 훅 메소드를 적절히 사용해서 전체적인 알고리즘의 뼈대를 유지하되 유연하게 기능을 변경 할 수 있도록 하고자 할 때 사용한다.

이번에 내가 설계한 template method pattern예제는 프로그래밍 시스템이다. c언어와 자바언어를 작성할 때 각각 맞는 툴은 다르지만 코드를 작성하고 컴파일하는 전체적인 구조는 같기 때문에 선정하였다.

 

 

2. 코드 설명

1)client 클래스

client 클래스에서 시스템이 시작한다. programming클래스를 상속받은 cjava programming클래스를 이용하여 각각의 언어에 맞는 프로그래밍을 한다.

public class client {

public static void main(String[]args) {

programming cp = new CProgramming();

programming jp = new JavaProgramming();

cp.working();

System.out.println();

jp.working();

}

}

 

 

2)programming 추상 클래스

programming 추상 클래스는 시스템에서 전체적인 골격을 잡아주는 역할을한다. 코드작성과 컴파일부분은 같기 때문에 하나로 작성하였고 개발툴은 다르기 때문에 추상 메소드로 만들었다.

abstract public class programming {

public void working() {

intro();

tool();

System.out.println("코드를 작성한다.");

System.out.println("코드를 컴파일 한다.");

System.out.println("A+를 받는다.");

}

public abstract void tool();

public abstract void intro();

}

 

 

3)CProgramming 클래스

CProgramming 클래스는 programming클래스를 상속받아 c언어 개발에 맞는 visualstudio tool을 사용한다.

public class CProgramming extends programming{

public void intro() {

System.out.println("C프로그래밍 입니다.");

}

public void tool() {

System.out.println("Visual Studio를 실행한다.");

}

 

 

4)JavaProgramming

JavaProgramming 클래스는 programming클래스를 상속받아 c언어 개발에 맞는 eclipse tool을 사용한다.

public class JavaProgramming extends programming{

public void intro() {

System.out.println("java프로그래밍 입니다.");

}

public void tool() {

System.out.println("eclipse를 실행한다.");

}

 

 

3. 클래스다이어그램

 

 

4. 코드 실행결과

 

 

'학교공부' 카테고리의 다른 글

텔넷  (0) 2018.12.03
이해하기쉬운 command pattern 예제  (0) 2018.11.25
이해하기쉬운 bridge pattern 예제  (0) 2018.11.23
쉽게설명한 전자상거래 유형  (0) 2018.11.22
이해하기쉬운 abstract factory pattern 예제  (2) 2018.11.22

Telnet

원격에서 리눅스에 접속하는 프로그램의 이름이기도 하지만 원래 프로토콜의 이름이다.

텔넷을 사용하려면 텔넷 클라이언트와 텔넷 서버가 필요하다.

텔넷 클라이언트와 텔넷 서버가 설치되어 있는지 확인한다.

 

 

텔넷 클라이언트와 텔넷 서버가 설치되어 있는지 확인(서버와 클라이언트가 설치되어 있다.)

rpm -qa | grep telnet

 

텔넷 서버 활성화하기

명령어 : systemctl start telnet.soket

 

위와 같은 화면이 나온 후 텔넷 서버가 활성화 된다.

 

페도라18까지는 telnet-server를 설치하면 의존패키지로 xinetd도 함께 설치 되었다. 하지만 페도라 19버전부터 텔넷이 혼자서 동작하는 standalone데몬에 동작하게 되었다. 페도라 19이전버전에서는 xinetd도 활성화 시켜줘야한다.

 

텔넷 접속하기

텔넷에 접속하기 위해서 'telnet ip주소'를 입력하면된다.

* telnet 0 이라고치면 로컬호스트로 접속한다.

 

1. 내가 설계한 Command pattern 예제

제목 : 돌려 돌려 선풍기

Command pattern이란 classobject들이 상호작용하는 방법과 책임을 분산하는 방법을 정의한 것이다. 여러 가지 행위 관련 pattern을 사용하여 독립적으로 일을 처리하고자 할 때 사용한다.

이번 과제에서 내가 설계한 Command patern예제는 선풍기이다. 선풍기는 바람을 일으키는 기능 이외에 회전이라는 별도의 기능이 따로 있다. 그렇기 때문에 이번 과제인 Command pattern예제로 선정하였다. 선풍기 프로그램의 클래스는 총 7가지이다. 하나하나 살펴보겠다.

 

 

1) client클래스

client클래스는 프로그램이 처음 시작하는 클래스이다. client클래스에서 바람을 일으키는 button1과 회전을 시키는 button2를 생성하여 이용자는 pressed()함수를 이용하여 해당 버튼의 기능을 수행한다.

public class client {

public static void main(String[] args){

Wind wind = new Wind();

Command WindCommand = new WindCommand(wind);

Button button1 = new Button(WindCommand);

 

Rotation rotation = new Rotation();

Command RotationCommand = new RotationCommand(rotation);

Button button2 = new Button(RotationCommand);

 

button1.pressed();

button2.pressed();

button2.pressed();

button1.pressed();

button1.pressed();

}

}



 

2) Button클래스

Button클래스는 setCommand함수를 이용하여 어떤 버튼을 생성할 것인가에 대해 Command클래스를 설정 할 수 있고 pressed()함수를 이용하여 기능을 실행시킨다.

public class Button {

private Command theCommand;

public Button(Command theCommand){

setCommand(theCommand);

}

public void setCommand(Command newCommand){

this.theCommand = newCommand;

}

public void pressed(){

theCommand.execute();

}

}

 

 

 

3) Command클래스

각 기능의 Command를 수행시키는 매개체 역할을 하는 클래스이다.

public interface Command {

public abstract void execute();

}

 

 

 

4) WindCommand클래스

Command클래스를 상속받고 Wind클래스를 이용하여 execute()함수를 통해 바람을 일이키는 기능을 수행시키는 클래스이다.

public class WindCommand implements Command{

private Wind wind;

public WindCommand(Wind wind){

this.wind = wind;

}

public void execute(){

wind.start();

}

}

 

 

 

5) RotationCommand클래스

Command클래스를 상속받고 Rotation클래스를 이용하여 execute()함수를 통해 회전기능을 수행시키는 클래스이다.

public class RotationCommand implements Command{

private Rotation rotation;

public RotationCommand(Rotation rotation){

this.rotation = rotation;

}

public void execute(){

rotation.start();

}

}

 

 

 

6) Wind클래스

start()함수를 이용하여 power변수에 따라서 해당하는 기능을 수행한다.

power=0일 때, power1증가시키고 바람세기를 약으로 선풍기를 가동시킨다.

power=1일 때, power1증가시키고 바람세기를 강으로 선풍기를 가동시킨다.

power=2일 때, power0으로 초기화하고 선풍기를 중지시킨다.

public class Wind {

private int power = 0;

public void start(){

if(power == 0){

power++;

System.out.println("선풍기 가동 (바람세기:)");

}else if(power == 1){

power++;

System.out.println("선풍기 가동 (바람세기:)");

}else{

power =0;

System.out.println("선풍기 가동 중지");

}

}

}

 

 

 

7) Rotation클래스

start()함수를 이용하여 run변수에 따라서 해당하는 기능을 수행한다.

run=false일 때, runtrue로 바꾸고 선풍기를 회전시킨다.

run=true일 때, runfalse로 바꾸고 선풍기 회전을 중지시킨다.

public class Rotation {

private boolean run=false;

public void start(){

if(run==false){

run = true;

System.out.println("선풍기를 회전시킵니다.");

}else{

System.out.println("선풍기 회전을 중지시킵니다.");

run = false;

}

}

}

 


2. 선풍기 클래스다이어그램



 

3. 실행화면

button1.pressed(); #button1=바람

button2.pressed(); #button2=회전

button2.pressed();

button1.pressed();

button1.pressed();

 

1. 내가설계한 bridge pattern 예제

제목 : 카드결제 시스템

bridge pattern이란 새로 추가한 객체의 interface가 기존 시스템에 맞지 않을 경우 새로운 interface를 정의하지 않고 단지 조상 class만을 상속받아 classabstract method를 구현하면서 새로운객체가 가진 method와 데이터를 사용하는 것이다.

이번 과제에서 bridge patter의 예제로 카드 결제시스템을 선택하였다. 한 계열사의 인터넷 쇼핑몰에서 해당 계열사의 카드뿐만아니라 새로운 interface인 다른 계열사의 카드를 사용하기 때문에 brigde pattern을 사용해야겠다고 생각했다.

 

2. 코드 설명

1)client 클래스

client 클래스에서 프로그램이 시작된다. client가 상품을 결정했다고 가정하고 바로 knushop 클래스 객체를 생성하여 card 선택하고 계산한다.

public class client {

public static void main(String[]args) {

System.out.println("상품을 선택하였습니다.");

knushop kns = new knushop();

kns.discount_product();

}

}

 

2)knushop 클래스

knushop클래스는 생성자를 통해 어떤카드를 선택할지 선택하고 discount_product함수를 통해서 선택된 카드를 통해서 상품을 계산한다.

import java.util.Scanner;

 

public class knushop {

private String card;

public knushop() {

System.out.println("어떤카드로 계산하시겠습니까?");

System.out.println("1.knucard, 2.dccard");

Scanner sc = new Scanner(System.in);

String selectCard = sc.nextLine();

if(selectCard.equals("knucard")||selectCard.equals("1")) {

set_card("knucard");

}

else if(selectCard.equals("dccard")||selectCard.equals("2")) {

set_card("dccard");

}

else {

set_card("error");

}

}

public void discount_product() {

discount dc = new discount();

card cd = dc.return_card_object(this);

cd.discount();

}

public String get_card() {

return card;

}

public void set_card(String selectCard) {

card = selectCard;

}

}

 

3)discount 클래스

discount클래스는 선택된 카드의 이름에 따라 card객체를 결정하는 중간다리 역할을 한다.

public class discount {

public card return_card_object(knushop knushop) {

knushop kns = knushop;

if(kns.get_card().equals("knucard")) {

return new knucard();

}

else if(kns.get_card().equals("dccard")) {

return new dccardAdapter();

}

else {

return new error();

}

}

}

 

4)card 추상클래스

card 추상클래스는 discount함수를 통해서 knushop의 물건을 계산한다.

abstract class card {

public abstract void discount();

}

 

5)knucard 클래스

knucard클래스는 card클래스를 상속받아서 knu인터넷 쇼핑몰에서 knucard를 사용할 수 있게 해준다.

class knucard extends card {

public knucard() {

System.out.println("knucard가 선택되었습니다.");

}

public void discount() {

System.out.println("knucard로 계산하였습니다.");

}

}

 

6)dccardAdapter 클래스

dccardAdaptercard를 상속받고 knu인터넷 쇼핑몰의 인터페이스에 맞지않은 dccard를 사용할 수 있게 해주는 역할을 한다.

class dccardAdapter extends card{

private dccard dccard;

public dccardAdapter() {

dccard = new dccard();

}

public void discount() {

dccard.discount();

}

}

 

7)dccard 클래스

dccard클래스는 dccardAdapter를 통해서 dccardknu 인터넷 쇼핑몰에서 사용가능하게 된다.

class dccard {

public dccard() {

System.out.println("dc카드가 선택되었습니다.");

}

public void discount() {

System.out.println("dc카드로 계산하였습니다.");

}

}

 

8)error클래스

사용할 수 없는 카드가 선택될 때 오류메세지가 출력된다.

class error extends card{

public void discount() {

System.out.println("존재하지 않는 카드입니다.");

}

}

 

3. 클래스다이어그램


 

 

4. 코드 실행결과


 

전자상거래 유형

1. B2C(기업과 소비자간의 거래)

기업과 소비지간의 전자상거래로 현재 가장 많은 비중을 차지하는 유형이다. 사전적으로는 기업이 전자적 매체를 통신망과결합하여 소비자에게 재화나 용역을 거래하는 행위로 초기에는 물리적인 제품이 주를 이루었으나 최근 들어서는 디지털 상품을 비록하여 거래 물품 영역이 점점 확대되고 있다.


2. B2G(기업과 정부간의 거래)

기업과 정부간의 전자상거래 유형으로, 정부가 조달예정 상품을 인터넷 가상상점에 공시하고 기업들이 가상 상점을 통하여 공급할 상품을 확인하고 주요 거래를 성사하는 과정이 전형적인 업무를 이룬다.


3. B2B(기업들간의 거래)

기업들간의 전자상거래 유형으로 기업간의 업무처리를 사람의 이동과 종이서류가 아니고 디지털 매체로 하는 제반 과정을 의미한다. 불특정 기업들이 공개된 네트워크를 이용하여 이루어지는 마케팅 활동이다.


4. B2E(기업 내에서의 전자상거래)

기업 내의 경영자와 사원간의 유대감과 신뢰감의 향상을 목적으로 하는 것으로 사업들이 기업이 운영하는 혹은 위탁한 인터넷 쇼핑몰을 통해 필요한 물품을 구매할 있게 만든 시스템으로 발전하고 있다.


5. G2C(정부와 소비자간의 거래)

정부 기관과 소비자간에 전자상거래로 이는 정부의 행정서비스를 어디서나 온라인으로 서비스를 받게 되는 것으로 각종 증명서의 발급이나 세금 부과, 남부 업부, 사회복지급여의 지급 업무 등이 여기에 해당된다.


6. G2B(정부와 기업간의 전자상거래)

정부와 기업이 온라인 회선을 이용하여 각종 세금 또는 조달 업무 등을 수행하는데 활용하고 있다.


7. C2C(소비자와 소비자간의 거래)

소비자끼리 서로 인터넷을 이용하여 일대일의 거래를 하는 것을 의미한다 주로 경매나 벼룩시장 중고품 매매가 일반적이며 대표적인 모델은 미국의 eBay 우리나라의 옥션등이 있다.


8. C2B(소비자와 기업 간의 전자상거래)

C2B거래는 소비자가 거래의 주체가 되는 것이 다르다. 공동 구매 역경매 등이 여기에 속한다. 소비자가 기업에게 원하는 상품의 가격과 조건을 제시하는 거래 방식이다.


9. P2P(개인과 개인간의 전자상거래)

기존의 server to client 상반되는 개념으로 개인 개인이라는 뜻의 네트워크 용어에서 비롯되었다. 개인 pc간에 이루어지는 전자상거래를 의미한다


10.O2O(온라인 to 오프라인)

온라인 서비스나 스마트폰앱을 이용하여 실제 오프라인에서 영업 중인 가게를 소비자와 연결해주는 전자상거래

1. 내가 설계한 Abstract factory pattern 예제

제목 : kinder초콜릿공장

kinder초콜릿이란 과거에 에그몽 초콜릿처럼 달걀모양 초콜릿 안에 장난감이 들어있는 초콜릿을 말한다. Abstract factory pattern을 이용하여 kinder초콜릿 제조공장 프로그램을 만들었다. kinder초콜릿의 종류는 파랑색포장지를 한 blueKinder와 빨강색 포장지를 한 redKinder 2가지이다. 파랑색과 빨강색에는 각각 다른 장난감이 들어가 있다.

언어는 자바언어를 사용했고 에디터는 이클립스를 사용했다. 총 클래스는 11가지이다.


1) main클래스

main클래스는 프로그램이 처음 시작하는 클래스이다. get_kinder_type함수를 사용하여 kinder의 종류를 선택하여 거기에 맞는 foodFactory객체를 생성한다. 그리고 running함수를 이용하여 공장을 가동한다.

public class main {

public static void main(String args[]) {

foodFactory foodfactory;

Kinder kinder = new Kinder();

if(kinder.get_kinder_type().equals("blue")){

foodfactory = new blueKinderFactory();

kinder.running(foodfactory);;

}

else if(kinder.get_kinder_type().equals("red")){

foodfactory = new redKinderFactory();

kinder.running(foodfactory);;

}

else {

System.out.println("error \n 공장 운행을 중단합니다.");

}

}

}

 

2) kinder클래스

kinder클래스는 kinder종류 선택과 foodFactory클래스 객체를 넘겨받아 running함수를 통해 공장을 가동한다.

import java.util.Scanner;

 

public class Kinder {

String _kinder_type;

public Kinder() {

Scanner sc = new Scanner(System.in);

System.out.println("어떤 킨더초콜릿을 생산하시겠습니까?(blue, red)");

this._kinder_type = sc.nextLine();

System.out.println(_kinder_type+" Kinder가 선택되었습니다.");

}

public void running(foodFactory foodfactory) {

foodfactory.return_toy_object();

foodfactory.return_label_object();

System.out.println("모든 작업이 완료되었으므로 공장을 종료합니다.");

}

public String get_kinder_type() {

return _kinder_type;

}

}

 

3) foodFactory클래스

생성자를 통해서 공장가동을 알리고 toy객체와 label객체를 반환한다.

public abstract class foodFactory {

 

public foodFactory() {

System.out.println("공장을 가동합니다.");

}

public abstract Toy return_toy_object();

public abstract Label return_label_object();

}

 

4) redKinderFactory클래스

foodFactory객체를 상속받아 toyPrincess객체와 labelredLabel객체를 반환한다.

public class redKinderFactory extends foodFactory {

public Toy return_toy_object() {

Princess princess = new Princess();

princess.production();

return princess;

}

public Label return_label_object() {

redLabel redlabel = new redLabel();

redlabel.packing();

return redlabel;

}

}

 

 

 

 

5) bleKinderFactory클래스

foodFactory객체를 상속받아 toySoldier객체와 labelbleLabel객체를 반환한다.

public class blueKinderFactory extends foodFactory{

 

public Toy return_toy_object() {

Soldier soldier = new Soldier();

soldier.production();

return soldier;

}

 

public Label return_label_object() {

blueLabel bluelabel = new blueLabel();

bluelabel.packing();

return bluelabel;

}

}

 

6) Toy클래스

생성자를 통해 장난감 생산을 알리고 prodctuion함수를 이용하여 장난감을 생산한다.

public abstract class Toy {

public Toy() {

System.out.println("장난감 생산 준비완료");

}

public abstract void production();

}

 

7) Soldier클래스

Toy클래스를 상속받고 생성자를 통해 soldier장난감 생산을 알리고 production함수를 통해서 장난감을 생산한다.

public class Soldier extends Toy{

public Soldier() {

System.out.println("군인 장난감을 생산합니다.");

}

public void production() {

System.out.println("군인 장난감이 생산되었습니다.");

}

}

 

8) Princess클래스

Toy클래스를 상속받고 생성자를 통해 Princess장난감 생산을 알리고 production함수를 통해서 장난감을 생산한다.

public class Princess extends Toy{

 

public Princess() {

System.out.println("공주 장난감을 생산합니다.");

}

public void production() {

System.out.println("공주장난감이 생산되었습니다.");

}

}

 

9) Label클래스

생성자를 통해서 포장지 생산준비를 알리고 packing함수를 통해서 포장한다.

public abstract class Label {

public Label() {

System.out.println("포장지 준비중");

}

public abstract void packing();

}

 

10) blueLabel클래스

생성자를 통해서 파란 포장지 생산을 알리고 packing함수를 통해서 포장지로 포장한다.

public class blueLabel extends Label{

 

public blueLabel() {

System.out.println("파랑 포장지 준비완료");

}

public void packing() {

System.out.println("kinder를 파란색으로 포장합니다.");

}

}

 

10) redLabel클래스

생성자를 통해서 빨간 포장지 생산을 알리고 packing함수를 통해서 포장지로 포장한다.

public class redLabel extends Label{

public redLabel() {

System.out.println("빨강 포장지 준비완료");

}

public void packing() {

System.out.println("kinder를 빨강색으로 포장합니다.");

}

}


2. 클래스다이어그램


3. 코드 실행 결과


'학교공부' 카테고리의 다른 글

이해하기쉬운 template method pattern 예제  (0) 2018.12.03
텔넷  (0) 2018.12.03
이해하기쉬운 command pattern 예제  (0) 2018.11.25
이해하기쉬운 bridge pattern 예제  (0) 2018.11.23
쉽게설명한 전자상거래 유형  (0) 2018.11.22
1.autorun.inf파일이란?
이동식 매체가 삽입되면 자동으로 특정한 동작을 수행하도록 하는기능을 하는 파일이다.



2. 생성방법
생성하는 방법은 메모장에 들어가서 다른이름으로 저장을 한 후 autorun.inf라고 이름을 설정하고 그 파일을 이동식매체(usb,외장하드) 안에 넣으면 된다.





3.autorun.inf파일의 구조



① [autorun] 
오토런파일을 설정하겠다는 하나의 선언문이다 이 단어를 써줘야 오토런파일이 실행된다.


② icon = icon.ico
저장매체 연결시 보이는 icon을 설정해주는 파일이다.




위와같이 이미지를 바꿀려면 autorun.inf파일과 icon파일을 동일한 위치에 넣어야한다.






③label=승환
저장매체의 이름을 설정한다.


④action=putty.exe
저장매체 실행시 자동으로 실행시킬 실행파일을 지정한다.
하지만 window7부터 보안상의 문제로 CD말고는 다 실행이 막혔다고합니다.


⑤open=putty.exe
저장매체 실행시 자동으로 실행시킬 실행파일을 지정한다.
하지만 window7부터 보안상의 문제로 CD말고는 다 실행이 막혔다고합니다.





이상으로 알면 쓸만한 신박한 잡지식 autorun.inf파일에 대해서 알아보았습니다.
 저장매체의 icon이미지를 바꿀때나 쓰겠네요 ㅎㅎㅎ


한글을 볼 수 있지만 키보드로 한글을 입력하려면 한글 입력기 설치가 따로 필요합니다.

그래서 이번에는 한글 입력기 설치를 해보겠습니다.
여기서 다루는 입력기는 fcitx입력기입니다.
(i-bus라는 입력기도있습니다.꼭 이 입력기를 사용하지 않아도됩니다. )


1. apt-get install fcitx-hangul (fcitx입력기 설치)






2. apt-get install fcitx-lib* (fcitx라이브러리 설치)






3. im-config(입력기설정)






4-1. 입력하면 이런표시가나온다.






4-2. yes버튼을 누른다.






4-3. fcitx부분을 선택하고 확인을 누른다.






4-4. 확인버튼 클릭






5. 바탕화면 우측상단 전원버튼 옆에 화살표를 누르고 설정버튼을 누른다.





6. 지역 및 언어를 선택한다






7. 아래사진과같이 옵션을 누르고 바꾼다.





8. fcitx-configtool (fcitx설정창)을 입력한다.





9-1. 아래사진같이 아무것도 뜨지 않는다면 reboot(재부팅) 후 다시 fcitx-configtool을 입력한다. (무엇인가 나온다면 9-2로가시면됩니다.)






9-2. 컴퓨터 마다 다르다 아래사진에서 Hangul만 남겨 놓고 지운다.





10. 그 후 추가 버튼(+)을 누르고 영어(또는 English)를 추가시킨다.





11. 이렇게하면 한글키 입력 패치가 완료됩니다.







부록 

1. apt-get install iceweasel-l10n-ko(파이어폭스 한글화패치)
칼리리눅스는 기본적으로 파이어폭스브라우저가 깔려있는데 아래 명령어는 영어로된 파이어폭스를 한글로 패치시켜준다.






2-1. 한영변환키 변경
fcitx-configtool에서 상단메뉴에 Global Config를 누르면 입력기 전환이라는 부분이보인다.
입력기 전환에 Ctrl+Space부분을 누른다.






2-2. 아래와같이 떳을때 윈하는 키를 입력한다.






문제점 : 키보드 한영키가 입력기전환에 입력이 안된다. 추후에 해결책을 다시 올리겠습니다.


+ Recent posts