Notice : 内容無保証。禁無断転載。リンク自由。

コンポーネント図

i_hello.h

#ifndef _i_hello_h_
#define _i_hello_h_

// 提供者が作成し、ユーザに公開する、Chello の interface

// <<interface>>

class Ihello{
public:
    virtual void Delete(void) = 0 ;
    virtual void greet(void) = 0 ;
} ;

// 操作 : プロトタイプ

Ihello* NewHello(void) ;

#endif /* _i_hello_h_ */

c_hello.h

#ifndef _c_hello_h_
#define _c_hello_h_

// 提供者が作成する、ユーザには非公開の、Chello の specification

#include <i_hello.h>

// <<imprementation>> <<specification>>

class Chello :
    public Ihello
{
public:
    void Delete(void) ;
    void greet(void) ;
} ;

#endif /* _c_hello_h_ */

hello.cpp

// 提供者が作成する、Chello の body と interface の実装

#include <stdio.h>
#include "c_hello.h"

// <<imprementation>> <<body>>

void Chello::Delete(void){
    delete this ;
}

void Chello::greet(void){
    printf("Hello, World!\n") ;
}

// 操作 : 実体

Ihello* NewHello(void){
    return new Chello ;
}

main.cpp

// ユーザが作成する、Chello のメンバを直接使用していないファイル。

#include <i_hello.h>

int main(void) {
    Ihello* hello = NewHello() ;

    hello->greet() ;
    hello->Delete() ;

    return 0 ;
}

戻る
トップページへ戻る