首页 \ 问答 \ Observer模式如何减少耦合?(How does the Observer pattern reduce coupling?)

Observer模式如何减少耦合?(How does the Observer pattern reduce coupling?)

我理解Observer模式是如何工作的,但是为什么Observer模式减少了软件设计中UI和业务逻辑组件之间的耦合?


I understand how the Observer pattern works, but why is it that the Observer pattern reduces coupling between UI and business logic components in software design?


原文:https://stackoverflow.com/questions/36868384
更新时间:2022-07-19 16:07

最满意答案

CTRL + Z被解释为文件结束标记。 一旦cin看到该标记,它就会进入错误状态( cin.eof()cin.fail()将为true ,这意味着(bool)cin将为false ,这就是你的第一个循环停止的原因)。 处于错误状态时, cin将不再接受任何输入。

要让cin回到良好状态,你可以调用cin.clear() 。 一旦它恢复到良好状态,它将再次接受输入。


CTRL+Z is interpreted as an end-of-file marker. Once cin sees that marker, it goes into an error state (cin.eof() and cin.fail() will be true, which means (bool)cin will be false, that's why your first loop stops). While in an error state, cin won't accept any more input.

To get cin back into a good state, you can call cin.clear(). Once it's back in a good state it will accept input once again.

相关问答

更多
  • if (cin.get() != '\n'); // **Line 2** // you have sth here -^ 删除那个分号。 如果它在那里, if语句基本上什么都不做。 此外,你没有测试用户是否确实输入了一个数字...如果我输入'd'怎么办? :) while(!(cin >> x)){ // woops, something has gone wrong... // display a message to tell the user he made a mistake // ...
  • 那么,如果你输入yes ,你似乎没有任何退出循环的方式,它只是打印test并继续其快乐的方式,试图读取更多的数据。 如果您的意思是第一次输入yes时不是打印test ,那么您需要临时更改: getline(cin,input); 至: getline (cin, input); cout << "[" << input << "]" << endl; 当你比较它时,试图找出缓冲区中的实际内容。 对于它的价值,这个代码(非常类似于你的)工作得很好: #include int mai ...
  • 为strings定义了一个getline : std::string line; std::getline(std::cin, line); There is a getline defined for strings: std::string line; std::getline(std::cin, line);
  • 尝试自己实现循环退出。 即替换 int sum3 = 0, p = 0; [...] while (std::cin >> p) { sum3 += p; } 通过 int sum3 = 0, p_; string p; [...] while (std::cin >> p) { if ( p == "exit" ) break; stringstream convert(p); if ( co ...
  • 使用getline ,然后处理字符串。 如果用户输入空行,则该字符串将为空。 如果没有,您可以对字符串进行进一步处理。 你甚至可以将它放在一个istringstream ,并将其视为来自cin 。 这是一个例子: std::queue data_q; while (true) { std::string line; std::getline(std::cin, line); if (line.empty()) // line is empty, empty the ...
  • 问题是isdigit()接受一个字符,而不是一个整数。 当字符为'0' , '1'等时,它返回true ...其ascii值为48等... 请尝试这种方式: char a; while(cin>>a){ if(!isdigit(a)){ The problem is that isdigit() takes a character, not an integer. It returns true when the character is '0', '1', etc... Which has as ...
  • istream::get()和istream::get(char&)的返回值不同 : int istream::get(); istream& istream::get (char& c); 所以没有参数的重载会返回read char的值,而带参数的重载会返回对同一个istream的引用,这使链接成为可能。 The return values of istream::get() and istream::get(char&) differ: int istream::get(); istream& ist ...
  • CTRL + Z被解释为文件结束标记。 一旦cin看到该标记,它就会进入错误状态( cin.eof()和cin.fail()将为true ,这意味着(bool)cin将为false ,这就是你的第一个循环停止的原因)。 处于错误状态时, cin将不再接受任何输入。 要让cin回到良好状态,你可以调用cin.clear() 。 一旦它恢复到良好状态,它将再次接受输入。 CTRL+Z is interpreted as an end-of-file marker. Once cin sees that mark ...
  • 如果你输入cout,你会得到一个“{”,因为它是它在这里读到的最后一个字符串: cin >> input; //check to make sure it's "{" 然后你将你的数字放入intInput。 您可以在整个时间用字符串读取输入,如果它不等于“}”则将其转换为整数 #include while (cin >> input) { if(input == "}") break; else intInput = atoi(input. ...
  • 问题是>>当遇到第一个空白字符时,操作符停止读取,但为什么在这种情况下它输出完整的输入字符串,即使我们的字符串中有空格也是如此 因为你在循环中使用它。 所以每次cin吃一个你打印的单词并丢弃空白。 您在每个单词后面打印换行符这一事实意味着您不希望看到空格 - 实际上s包含空格。 测试这个的简单方法是打印: cout << s << "$"; 然而,代码最有趣的特性是while如何测试由<<返回的istream返回的值,它在布尔上下文中准确地产生你想要的:输入是否完成。 The problem is >> ...

相关文章

更多

最新问答

更多
  • sp_updatestats是否导致SQL Server 2005中无法访问表?(Does sp_updatestats cause tables to be inaccessible in SQL Server 2005?)
  • 如何创建一个可以与持续运行的服务交互的CLI,类似于MySQL的shell?(How to create a CLI that can interact with a continuously running service, similar to MySQL's shell?)
  • AESGCM解密失败的MAC(AESGCM decryption failing with MAC)
  • Zurb Foundation 4 - 嵌套网格对齐问题(Zurb Foundation 4 - Nested grid alignment issues)
  • 湖北京山哪里有修平板计算机的
  • SimplePie问题(SimplePie Problem)
  • 在不同的任务中,我们可以同时使用多少“上下文”?(How many 'context' we can use at a time simultaneously in different tasks?)
  • HTML / Javascript:从子目录启用文件夹访问(HTML/Javascript: Enabling folder access from a subdirectory)
  • 为什么我会收到链接错误?(Why do I get a linker error?)
  • 如何正确定义析构函数(How to properly define destructor)
  • 垂直切换菜单打开第3级父级。(Vertical toggle menu 3rd level parent stay opened. jQuery)
  • 类型不匹配 - JavaScript(Type mismatch - JavaScript)
  • 为什么当我将模型传递给我的.Net MVC 4控制器操作时,它坚持在部分更新中使用它?(Why is it that when I pass a Model to my .Net MVC 4 Controller Action it insists on using it in the Partial Update?)
  • 在使用熊猫和statsmodels时拉取变量名称(Pulling variable names when using pandas and statsmodels)
  • 如何开启mysql计划事件
  • 检查数组的总和是否大于最大数,反之亦然javascript(checking if sum of array is greater than max number and vice versa javascript)
  • 使用OpenGL ES绘制轮廓(Drawing Outline with OpenGL ES)
  • java日历格式(java Calendar format)
  • Python PANDAS:将pandas / numpy转换为dask数据框/数组(Python PANDAS: Converting from pandas/numpy to dask dataframe/array)
  • 如何搜索附加在elasticsearch索引中的文档的内容(How to search a content of a document attached in elasticsearch index)
  • LinQ to Entities:做相反的查询(LinQ to Entities: Doing the opposite query)
  • 从ExtJs 4.1商店中删除记录时会触发哪些事件(Which events get fired when a record is removed from ExtJs 4.1 store)
  • 运行javascript后如何截取网页截图[关闭](How to take screenshot of a webpage after running javascript [closed])
  • 如何使用GlassFish打印完整的堆栈跟踪?(How can I print the full stack trace with GlassFish?)
  • 如何获取某个exe应用程序的出站HTTP请求?(how to get the outbound HTTP request of a certain exe application?)
  • 嗨,Android重叠背景片段和膨胀异常(Hi, Android overlapping background fragment and inflate exception)
  • Assimp详细说明typedef(Assimp elaborated type refers to typedef)
  • 初始化继承类中不同对象的列表(initialize list of different objects in inherited class)
  • 使用jquery ajax在gridview行中保存星级评分(Save star rating in a gridview row using jquery ajax)
  • Geoxml3 groundOverlay zIndex(Geoxml3 groundOverlay zIndex)