Flyweight

// Contact.h

#ifndef _CONTACT_H

#define _CONTACT_H

#include <string>

using namespace std;

class Contact {

private:

string Name;

string TEL;

public:

Contact(string myName, string myTEL);

inline const string get_Name() const;

inline const string get_TEL() const;

void set_Name(string value);

void set_TEL(string value);

};

inline const string Contact::get_Name() const {

return this->Name;

}

inline const string Contact::get_TEL() const {

return this->TEL;

}

#endif

說明

    • 設計『陣列類別』生成基底類別物件。

// FlyweightContact.h

#ifndef _FLYWEIGHTCONTACT_H

#define _FLYWEIGHTCONTACT_H

#include <string>

using namespace std;

#include <vector>

using namespace std;

class Contact;

class FlyweightContact {

public:

FlyweightContact();

void addList(string myName, string myTEL);

private:

vector<Contact> contactList;

public:

void printList();

};

#endif