??C++ ????????????????
???????????? ???????[ 2014/10/31 13:58:53 ] ????????C++ ??????? MVC ????
#ifndef SUBJECT_H
#define SUBJECT_H
#include<list>
#include "observer.h"
using namespace std;
class Observer;
class Blog
{
private:
list<Observer *> m_observers; //??????б?
protected:
string m_status; //??
public:
Blog() {}
virtual ~Blog() {}
void Attach(Observer *observer); //???????
void Remove(Observer *observer); //????????
void Notify(); //???????
virtual void SetStatus(string s); //??????
virtual string GetStatus(); //?????
};
class BlogCSDN : public Blog
{
private:
string m_name; //????????
public:
BlogCSDN(string name) : m_name(name) {}
~BlogCSDN() {}
void SetStatus(string s);
string GetStatus();
};
#endif
subject.cpp
#include "subject.h"
void Blog::Attach(Observer *observer)
{
m_observers.push_back(observer);
}
void Blog::Remove(Observer *observer)
{
m_observers.remove(observer);
}
void Blog::Notify()
{
list<Observer *>::iterator iter = m_observers.begin();
for(; iter != m_observers.end(); iter++) {
(*iter)->Update();
}
}
void Blog::SetStatus(string s)
{
m_status = s;
}
string Blog::GetStatus()
{
return m_status;
}
void BlogCSDN::SetStatus(string s)
{
m_status = "csdn??: " +m_name + s;
}
string BlogCSDN::GetStatus()
{
return m_status;
}
main.cpp
#include "observer.h"
#include "subject.h"
int main()
{
Blog *blog = new BlogCSDN("zy416548283");
Observer *observer = new ObserverBlog("tutupig"?? blog);
blog->Attach(observer);
blog->SetStatus("??????????????????");
blog->Notify();
delete blog;
delete observer;
return 0;
}
????????????:
????zy@zyPc:~/code/Cplus/designPattern/observer$ ./a.out
????tutupig-------csdn??: zy416548283????***????
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
??C++????????????C++ lvalue??rvalueC++11????????C++???????????????C++?е?????????????????C++?????????C++???Windows????λ??C/C++???????????????????JAVA??C??C++??????????c++??python???????????????????????????????C++???????C++?е????????C++????????????????C++ ???????????????C++?????????????????????C++????????????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????