Interface General .NET2008/02/19 00:14
Interface란?
- 클래스의 한 종류
- 클래스의 뼈대만 가지고 있음.
Interface의 구성요소
- 메소드, 속성, 이벤트, 인덱서
- 선언만 가능
Interface의 접근자
- 기본적으로 public
Interface의 상속
- 중복상속, 단일 상속이 가능
Interface를 사용하는 목적
- 그것은 구현(Implementation)을 하기 위함이다.
- 이것은 비완전한 클래스 이므로 완전해지기 위해 구현을 해야 한다.
- 반드시 내부의 구현되지 않은 모든 멤버를 구현해야 한다.
- 인터페이스는 클래스에서 구현되어야 한다.
인터페이스의 구현 예)
using System;
using System.Collections.Generic;
using System.Text;
namespace CA_Interface
{
interface IPrint
{
void SetUp();
void PowerOn();
void PowerOff();
void LowPrint();
void MidPrint();
void FastPrint();
}
public class Program : IPrint
{
public void SetUp() {
Console.WriteLine("프린트 설정을 준비중!");
Console.ReadLine();
return;
}
public void PowerOn() {
Console.WriteLine("프린트 파워를 켜는 중!");
Console.ReadLine();
return;
}
public void PowerOff() {
Console.WriteLine("프린트 파워를 끄는 중");
Console.ReadLine();
return;
}
public void LowPrint() {
Console.WriteLine("느린 속도로 인쇄하는 중");
Console.ReadLine();
return;
}
public void MidPrint() {
Console.WriteLine("중간 속도로 인쇄하는 중");
Console.ReadLine(); Console.ReadLine();
return;
}
public void FastPrint() {
Console.WriteLine("빠른 속도로 인쇄하는 중");
Console.ReadLine();
return;
}
static void Main(string[] args)
{
IPrint ip = new Program();
ip.SetUp();
}
}
}
인터페이스 + 인터페이스(속성)의 예)
using System;
using System.Collections.Generic;
using System.Text;
namespace CA_Interface
{
interface IPowerOn
{
int IFlag
{
get;
set;
}
}
interface IPrint
{
void SetUp();
void PowerOn();
void PowerOff();
void LowPrint();
void MidPrint();
void FastPrint();
}
public class Program : IPrint, IPowerOn
{
public void SetUp() {
Console.WriteLine("Ready, Print Setup");
Console.ReadLine();
return;
}
public void PowerOn() {
Console.WriteLine("Print Power On");
Console.ReadLine();
return;
}
public void PowerOff() {
Console.WriteLine("Print Power Off");
Console.ReadLine();
return;
}
public void LowPrint() {
Console.WriteLine("Doing Low Speed Print");
Console.ReadLine();
return;
}
public void MidPrint() {
Console.WriteLine("Doing Miduam Speed Print");
Console.ReadLine(); Console.ReadLine();
return;
}
public void FastPrint() {
Console.WriteLine("Doing Fast Speed Print");
Console.ReadLine();
return;
}
private int iflag = 0;
public int IFlag
{
get {
return iflag;
}
set {
iflag = value;
}
}
static void Main(string[] args)
{
IPrint ip = new Program();
ip.SetUp();
Program p = new Program();
p.IFlag = 1000;
}
}
}
'General .NET' 카테고리의 다른 글
| 닷넷의 소켓 클래스 (0) | 2008/04/11 |
|---|---|
| ASP.NET MVC Framework (0) | 2008/03/27 |
| Interface (0) | 2008/02/19 |
| Interface란? (0) | 2008/02/18 |
| 스마트클라이언트 서명키 만들기 (0) | 2008/02/17 |
| 닷넷으로 다국어 지원 폼 만들기 (0) | 2008/02/12 |
