{"id":3575,"date":"2012-07-12T08:48:16","date_gmt":"2012-07-11T23:48:16","guid":{"rendered":"http:\/\/www.moonmile.net\/blog\/archives\/3575"},"modified":"2012-07-12T01:49:04","modified_gmt":"2012-07-11T16:49:04","slug":"2%e3%81%a4%e3%81%aeview%e3%81%ae%e5%a4%89%e6%9b%b4%e3%81%8c%e3%80%81%e5%90%8c%e6%99%82%e3%81%ab%e8%a1%8c%e3%82%8f%e3%82%8c%e3%82%8b%e3%81%a8%e3%81%8d%e3%81%aemodel%e3%81%ae%e6%8c%99%e5%8b%95%e3%82%92","status":"publish","type":"post","link":"http:\/\/www.moonmile.net\/blog\/archives\/3575","title":{"rendered":"2\u3064\u306eView\u306e\u5909\u66f4\u304c\u3001\u540c\u6642\u306b\u884c\u308f\u308c\u308b\u3068\u304d\u306eModel\u306e\u6319\u52d5\u3092\u8003\u5bdf"},"content":{"rendered":"<p>\n\u5177\u4f53\u7684\u306b\u8a00\u3048\u3070\u3001\u4ee5\u4e0b\u306e\u72b6\u6cc1\u3092\u5b9f\u73fe\u3055\u305b\u307e\u3059\u3002\n<\/p>\n<p>\n\u25a0\u76ee\u7684\n<\/p>\n<ul>\n<li>GridView \u3068 GraihpcsView \u306e 2\u3064\u306e View \u304c\u3042\u308b\u3002<\/li>\n<li>GridView \u306e\u9805\u76ee\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u3068\u3001GraphicsView \u306e\u3042\u308b\u70b9\u304c\u53cd\u8ee2\u3059\u308b\u3002<\/li>\n<li>\u9006\u306b GraphicsView \u306e\u3042\u308b\u70b9\u3092\u53cd\u8ee2\u3055\u305b\u308b\u3068\u3001GridView \u306e\u9805\u76ee\u306e\u30c1\u30a7\u30c3\u30af\u304c\u53cd\u8ee2\u3059\u308b\u3002<\/li>\n<\/ul>\n<p>\n\u3068\u3044\u3046\u30012\u3064\u306eView\u306e\u76f8\u4e92\u4f1d\u64ad\u3092\u5b9f\u88c5\u3057\u307e\u3059\u3002\n<\/p>\n<p>\n\u25a0\u5236\u9650\n<\/p>\n<p>\nC# \u3067\u3084\u308b\u306e\u304c\u826f\u3044\u306e\u3067\u3057\u3087\u3046\u304c\u3001\u624b\u5143\u306e\u8ab2\u984c\u304c C++ \u306a\u306e\u3067\u3001C++ \u3067\u5b9f\u88c5\u3057\u307e\u3059\u3002<br \/>\n\u3044\u3084\u3001C# \u3067\u66f8\u3044\u3066\u304b\u3089 C++ \u306b\u66f8\u304d\u76f4\u3057\u305f\u307b\u3046\u304c\u65e9\u3044\u304b\u306a\uff1f\u3053\u308c\u306f\u3001\u691c\u8a0e\u3092\u9032\u3081\u306a\u304c\u3089\u3002\n<\/p>\n<p>\n\u25a0\u307e\u305a\u306f Model \u3092\u4f5c\u308b\u3002\n<\/p>\n<p>\n2 \u3064\u306e View \u306f\u540c\u3058 Model \u3092\u5171\u6709\u3057\u3066\u3044\u308b\u3068\u3044\u3046\u524d\u63d0\u3092\u4f5c\u308a\u307e\u3059\u3002\u76f4\u63a5 View \u540c\u58eb\u304c\u7e4b\u304c\u3063\u3066\u3044\u308b\u3068\u3044\u3046\u30b9\u30bf\u30fc\u30c8\u5730\u70b9\u3067\u3082\u3088\u3044\u306e\u3067\u3059\u304c\u3001\u305d\u308c\u306f\u6614\u306e\u8a71\u3002\u305d\u306e\u3042\u305f\u308a\u306f\u7aef\u6298\u3063\u3066\u3001Model -> View \u3068\u3044\u3046\u5206\u96e2\u3092\u5ff5\u982d\u306b\u5165\u308c\u307e\u3059\u3002\n<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nclass Model \n{\npublic:\n\tint gridid;\n\tfloat x;\n\tfloat y;\n\tfloat z;\n\tbool selected;\n};\n<\/pre>\n<p>\n\u3072\u3068\u307e\u305a\u3001POJO \u306a\u30c7\u30fc\u30bf\u30af\u30e9\u30b9\u3092\u4f5c\u308a\u307e\u3059\u3002x,y,z \u306f\u4e09\u6b21\u5143\u30c7\u30fc\u30bf\u306e\u4f4d\u7f6e\u60c5\u5831\u3001gridid \u304c\u8b58\u5225\u5b50\u3067\u3001selected \u304c\u9078\u629e\u72b6\u614b\u3067\u3059\u306d\u3002<br \/>\n\u3053\u308c\u3092\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u3068\u3057\u3066\u6271\u3046\u306e\u3067\u3001\n<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nclass Models : public vector&lt;Model*&gt;\n{\n};\n<\/pre>\n<p>\n\u306a\u611f\u3058\u306b\u3057\u307e\u3059\u3002\u4eca\u56de\u306f\u633f\u5165\/\u524a\u9664\u3092\u8003\u3048\u306a\u3044\u306e\u3067 vector \u3067\u3088\u3044\u304b\u3068\u3002\n<\/p>\n<p>\n\u25a0GridView \u3092\u4f5c\u308b\n<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nclass GridView \n{\npublic:\n\tModels *models;\npublic:\n\tvoid print() {\n\t\tif ( models == NULL ) return;\n\t\tfor ( auto it = models-&gt;begin(); it != models-&gt;end(); ++it ) {\n\t\t\tModel *m = *it;\n\t\t\tcout &lt;&lt; m-&gt;gridid &lt;&lt; &amp;quot;:&amp;quot; &lt;&lt; m-&gt;selected &lt;&lt; endl;\n\t\t}\n\t}\n\tvoid onChecked( int row, bool selected ) {\n\t\tif ( models == NULL ) return ;\n\t\tfor ( auto it = models-&gt;begin(); it != models-&gt;end(); ++it ) {\n\t\t\tif ( row == 0 ) {\n\t\t\t\tModel *m = *it;\n\t\t\t\tm-&gt;selected = selected;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\trow --;\n\t\t}\n\t}\n};\n<\/pre>\n<p>\nfor \u6587\u3067\u5efb\u3057\u3066\u3044\u308b\u3068\u3053\u308d\u304c\u30c0\u30b5\u3044\u3067\u3059\u304c\u3001\u3072\u3068\u307e\u305a\u8868\u793a\u7528\u306e print \u95a2\u6570\u3068\u3001\u9805\u76ee\u3092\u30c1\u30a7\u30c3\u30af\u3057\u305f\u6642\u306e onChecked \u95a2\u6570\u3092\u4f5c\u3063\u3066\u304a\u304d\u307e\u3059\u3002<br \/>\nonCheced \u95a2\u6570\u3067\u306f\u3001\u884c\u756a\u53f7\u3092\u6e21\u3059\u3088\u3046\u306b\u3057\u307e\u3059\u3002\n<\/p>\n<p>\nModels \u3092\u5185\u90e8\u306b\u6301\u3064\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u304c\u3001\u3053\u308c\u306f\u5f8c\u304b\u3089\u5206\u96e2\u3055\u305b\u305f\u3044\u3068\u3053\u308d\u3067\u3059\u3002\n<\/p>\n<p>\n\u25a0GraphicsView \u3092\u4f5c\u308b\n<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nclass GraphicsView \n{\npublic:\n\tModels *models;\npublic:\n\tvoid print() {\n\t\tif ( models == NULL ) return;\n\t\tfor ( auto it = models-&gt;begin(); it != models-&gt;end(); ++it ) {\n\t\t\tModel *m = *it;\n\t\t\tcout &lt;&lt; m-&gt;gridid &lt;&lt; &amp;quot;:&amp;quot; &lt;&lt; m-&gt;selected &lt;&lt; endl;\n\t\t}\n\t}\n\tvoid onClick( int gridid ) {\n\t\tif ( models == NULL ) return ;\n\t\tfor ( auto it = models-&gt;begin(); it != models-&gt;end(); ++it ) {\n\t\t\tModel *m = *it;\n\t\t\tif ( m-&gt;gridid == gridid ) {\n\t\t\t\tm-&gt;selected = !m-&gt;selected;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n};\n<\/pre>\n<p>\n\u57fa\u672c\u52d5\u4f5c\u306f GridView \u3068\u540c\u3058\u3067\u3059\u304c\u3001onClick \u3067\u6e21\u3055\u308c\u308b\u306e\u306f gridid \u306b\u3057\u3066\u304a\u304d\u307e\u3059\u3002\n<\/p>\n<p>\n\u25a0\u76f8\u4e92\u4f1d\u64ad\u3092\u5b9f\u88c5\u3059\u308b\n<\/p>\n<p>\n\u3055\u3066\u3001GridView::onChecked \u3068 GraphicsView::onClick \u304c\u76f8\u4e92\u306b\u9023\u643a\u3057\u3066\u308b\u3053\u3068\u304c\u5206\u304b\u308b\u306e\u3067\u3001\u3053\u308c\u3092\u7d20\u76f4\u306b\u9023\u643a\u3055\u305b\u307e\u3059\u3002\n<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nclass GrahicsView;\nclass GridView;\nstatic GraihpcsView *grahpicsView;\nstatic GridView *gridView;\n\nclass GridView \n{\npublic:\n\tModels *models;\npublic:\n\tvoid print() {\n\t\tif ( models == NULL ) return;\n\t\tfor ( auto it = models-&gt;begin(); it != models-&gt;end(); ++it ) {\n\t\t\tModel *m = *it;\n\t\t\tcout &lt;&lt; m-&gt;gridid &lt;&lt; &amp;quot;:&amp;quot; &lt;&lt; m-&gt;selected &lt;&lt; endl;\n\t\t}\n\t}\n\tvoid onChecked( int row, bool selected ) {\n\t\tif ( models == NULL ) return ;\n\t\tfor ( auto it = models-&gt;begin(); it != models-&gt;end(); ++it ) {\n\t\t\tif ( row == 0 ) {\n\t\t\t\tModel *m = *it;\n\t\t\t\tm-&gt;selected = selected;\n\t\t\t\tgraphicsView-&gt;onClick( m-&gt;gridid ); \/\/ NG\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\trow --;\n\t\t}\n\t}\n};\n\nclass GraphicsView \n{\npublic:\n\tModels *models;\npublic:\n\tvoid print() {\n\t\tif ( models == NULL ) return;\n\t\tfor ( auto it = models-&gt;begin(); it != models-&gt;end(); ++it ) {\n\t\t\tModel *m = *it;\n\t\t\tcout &lt;&lt; m-&gt;gridid &lt;&lt; &amp;quot;:&amp;quot; &lt;&lt; m-&gt;selected &lt;&lt; endl;\n\t\t}\n\t}\n\tvoid onClick( int gridid ) {\n\t\tif ( models == NULL ) return ;\n\t\tint row = 0;\n\t\tfor ( auto it = models-&gt;begin(); it != models-&gt;end(); ++it ) {\n\t\t\tModel *m = *it;\n\t\t\tif ( m-&gt;gridid == gridid ) {\n\t\t\t\tm-&gt;selected = !m-&gt;selected;\n\t\t\t\tgraphicsView-&gt;onClick( row, m-&gt;selected ); \/\/ NG\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\trow ++;\n\t\t}\n\t}\n};\n<\/pre>\n<p>\n\u4e00\u898b\u3001\u826f\u3055\u305d\u3046\u306b\u898b\u3048\u307e\u3059\u304c\u3001\u7247\u65b9\u304c\u547c\u3073\u51fa\u3055\u308c\u308b\u3068\u5e38\u306b\u3082\u3046\u7247\u65b9\u304c\u547c\u3073\u51fa\u3055\u308c\u3001\u518d\u3073\u7247\u65b9\u3092\u547c\u3073\u51fa\u3059\u3068\u3044\u3046\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u7121\u9650\u4f1d\u64ad\u306b\u9665\u3063\u3066\u3057\u307e\u3063\u3066\u99c4\u76ee\u3067\u3059\u3002<br \/>\n\u307e\u305f\u3001C++ \u306e\u5834\u5408\u3053\u306e onClick \u3068 onChecked \u306e\u30b3\u30f3\u30d1\u30a4\u30eb\u3092\u901a\u3059\u306e\u306f\u7d50\u69cb\u56f0\u96e3\u3067\u3059\u3002\u30af\u30e9\u30b9\u3092\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u5ba3\u8a00\u306b\u3057\u306a\u3044\u3068\u99c4\u76ee\u3067\u3059\u306d\u3002C#\u306a\u3089\u3070\u3001\u3053\u306e\u307e\u307e\u3067\u3082\u30b3\u30f3\u30d1\u30a4\u30eb\u306f\u901a\u308a\u307e\u3059\u304c\u3001\u3084\u3063\u3071\u308a\u3001\u7121\u9650\u306b\u30e1\u30c3\u30bb\u30fc\u30b8\u304c\u4f1d\u64ad\u3057\u3066\u3057\u307e\u3044\u307e\u3059\u3002<br \/>\n\u7121\u9650\u306b\u4f1d\u64ad\u3057\u306a\u3044\u3088\u3046\u306b\u30d5\u30e9\u30b0\u3092\u4ed8\u3051\u308b\u3053\u3068\u3082\u8003\u3048\u3089\u308c\u307e\u3059\u304c\u3001\u30d0\u30b0\u306e\u6e29\u5e8a\u3068\u306a\u308b\u306e\u3067\u3084\u3081\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002\u3053\u3053\u3067\u306f\u3001Model \u306e\u66f8\u304d\u63db\u3048\u3092\u3059\u308b\u3001\u305d\u3057\u3066 Model \u306e\u5909\u66f4\u304c\u901a\u77e5\u3055\u308c\u308b\u3001\u3068\u3044\u3046\u65b9\u5f0f\u306b\u4ee3\u3048\u3066\u3044\u304d\u307e\u3059\u3002\n<\/p>\n<ul>\n<li>GrahpicsView -> Model \u306e\u5909\u66f4<\/li>\n<li>GridView -> Model \u306e\u5909\u66f4<\/li>\n<li>Model -> GraphicsView \u3078\u5909\u66f4\u901a\u77e5<\/li>\n<li>Model -> GridView \u3078\u306e\u5909\u66f4\u901a\u77e5<\/li>\n<\/ul>\n<p>\n\u3068\u3044\u3046\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u6d41\u308c\u3067\u3059\u3002\u3053\u3046\u3059\u308b\u3053\u3068\u306b\u3088\u3063\u3066\u3001\n<\/p>\n<ol>\n<li>GraphicsView::OnClick \u3092\u547c\u3073\u51fa\u3059\u3002<\/li>\n<li>Model \u304c\u5909\u66f4\u3055\u308c\u308b\u3002<\/li>\n<li>Model \u304b\u3089 GridView \u3078\u5909\u66f4\u304c\u901a\u77e5\u3055\u308c\u308b\u3002<\/li>\n<li>Model \u304b\u3089 GraphicsView \u3078\u5909\u66f4\u304c\u901a\u77e5\u3055\u308c\u308b\u3002<\/li>\n<\/ol>\n<p>\n\u3068\u3044\u3046\u30d5\u30ed\u30fc\u306b\u306a\u308a\u307e\u3059\u30024\u756a\u76ee\u306f\u901a\u77e5\u3068\u3057\u3066\u306f\u7121\u99c4\uff08\u81ea\u5206\u3067 Model \u3092\u5909\u66f4\u3057\u3066\u3044\u308b\u306e\u3067\uff09\u306b\u306a\u308a\u307e\u3059\u304c\u3001GraphicsView \u3068 GridView \u3078\u306e\u5bfe\u79f0\u6027\u3092\u4fdd\u3064\u305f\u3081\u306b\u3053\u306e\u307e\u307e\u306b\u3057\u3066\u304a\u304d\u307e\u3059\u3002\n<\/p>\n<p>\n\u25a0Model \u306e\u5909\u66f4\u901a\u77e5\u3092\u5b9f\u88c5\u3059\u308b\n<\/p>\n<p>\nModel \u30af\u30e9\u30b9\u306f\u3001INotify \u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3092\u7d99\u627f\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u3001\u95a2\u6570\u30dd\u30a4\u30f3\u30bf\u3068\u3057\u3066 onChanged \u3092\u767b\u9332\u3055\u305b\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002\n<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nclass INotify\n{\npublic:\n\tvoid (*onChanged)(void *sender);\n\tvoid onProperyChanged( void *sender );\n};\n\nclass Model : public INotify\n{\npublic:\n\tint gridid;\n\tfloat x;\n\tfloat y;\n\tfloat z;\nprotected:\n\tbool selected;\npublic:\n\tbool getSelected() { return this-&gt;selected; }\n\tvoid setSelected( bool v ) {\n\t\tif ( this-&gt;selected != v ) {\n\t\t\tthis-&gt;selected = v;\n\t\t\tif ( onChanged != NULL ) {\n\t\t\t\tonChanged( this );\n\t\t\t}\n\t\t}\n\t}\t\t\npublic:\n\tModel( int id, float x, float y, float z ) {\n\t\tthis-&gt;gridid = id;\n\t\tthis-&gt;x = x;\n\t\tthis-&gt;y = y;\n\t\tthis-&gt;z = z;\n\t\tthis-&gt;selected = false;\n\t}\n};\n<\/pre>\n<p>\n\u3053\u3046\u3084\u3063\u3066\u304a\u3044\u3066\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306b onChanged \u306b\u767b\u9332\u3057\u305f\u3044\u3068\u3053\u308d\u306a\u306e\u3067\u3059\u304c\u3001\u5b9f\u969b\u306f\u3046\u307e\u304f\u30b3\u30f3\u30d1\u30a4\u30eb\u304c\u901a\u308a\u307e\u305b\u3093\u3002\n<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nclass GridView : public INotify\n{\npublic:\n\tModels *models;\npublic:\n\tGridView() {\n\t\tthis-&gt;onChanged = &amp;GridView::onProperyChanged;\t\/\/ compile error\n\t}\n\n\tvoid print() {\n\t\tif ( models == NULL ) return;\n\t\tfor ( auto it = models-&gt;begin(); it != models-&gt;end(); ++it ) {\n\t\t\tModel *m = *it;\n\t\t\tcout &lt;&lt; m-&gt;gridid &lt;&lt; &amp;quot;:&amp;quot; &lt;&lt; m-&gt;getSelected() &lt;&lt; endl;\n\t\t}\n\t}\n\tvoid onChecked( int row, bool selected ) {\n\t\tif ( models == NULL ) return ;\n\t\tfor ( auto it = models-&gt;begin(); it != models-&gt;end(); ++it ) {\n\t\t\tif ( row == 0 ) {\n\t\t\t\tModel *m = *it;\n\t\t\t\t\/\/ m-&gt;selected = selected;\n\t\t\t\tm-&gt;setSelected( selected );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\trow --;\n\t\t}\n\t}\n\tvoid onProperyChanged( void *sender )\n\t{\n\t\tauto model = (Model*)sender;\n\t\tcout &lt;&lt; &amp;quot;GridView::onChanged: &amp;quot; &lt;&lt; model-&gt;gridid &lt;&lt; endl;\t\n\t}\n};\n<\/pre>\n<p>\nalice018.cpp(56) : error C2440: &#8216;=&#8217; : &#8216;void (__thiscall GridView::* )(void *)&#8217; \u304b\u3089 &#8216;void (__cdecl *)(void *)&#8217; \u306b\u5909\u63db\u3067\u304d\u307e\u305b\u3093\u3002\u3053\u306e\u5909\u63db\u304c\u53ef\u80fd\u306a\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u306f\u3042\u308a\u307e\u305b\u3093\u3002\n<\/p>\n<p>\n\u306e\u3088\u3046\u306a\u30b3\u30f3\u30d1\u30a4\u30eb\u30a8\u30e9\u30fc\u304c\u3067\u307e\u3059\u3002\u89aa\u30af\u30e9\u30b9\u540d\u304c\u5165\u3063\u3066\u3057\u307e\u3046\u306e\u3067\u67d4\u8edf\u6027\u304c\u5931\u308f\u308c\u3066\u3057\u307e\u3063\u305f\u306e\u3067\u3059\u3002\u307e\u3041\u3001\u53b3\u5bc6\u306a\u578b\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u5206\u306b\u306f\u3053\u3061\u3089\u306e\u307b\u3046\u304c\u826f\u3044\u306e\u3067\u306f\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002<br \/>\n\u307e\u305f\u3001\u3053\u306e onChanged \u30a4\u30d9\u30f3\u30c8\u306f\u3001\u3072\u3068\u3064\u306e View \u306b\u5bfe\u3057\u3066\u3057\u304b\u901a\u77e5\u304c\u3067\u304d\u307e\u305b\u3093\u3002\u4eca\u56de\u306e\u5834\u5408\u306e\u3088\u3046\u306b\u3001GrapihcView, GridView \u3078\u540c\u6642\u306b\u901a\u77e5\u3059\u308b\u3068\u3044\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u305b\u3093\u3002\n<\/p>\n<p>\n __event \u3068 __hook \u3092\u4f7f\u3063\u3066 mvvm \u3092\u5b9f\u88c5\u3057\u3066\u307f\u308b | Moonmile Solutions Blog<br \/>\n<a href=\"http:\/\/www.moonmile.net\/blog\/archives\/3559\">http:\/\/www.moonmile.net\/blog\/archives\/3559<\/a>\n<\/p>\n<p>\n\u306a\u306e\u3067\u3001\u4eca\u56de\u306f\u7d20\u76f4\u306b __event\/__hook \u3092\u4f7f\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002\n<\/p>\n<p>\n\u25a0Model \u306e\u5b9f\u88c5\u3092\u3084\u308a\u76f4\u3059\n<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nclass INotify\n{\npublic:\n\t__event void onChanged(void *sender);\n};\nclass ITarget\n{\npublic:\n\tvoid onPropertyChanged( void *sender );\n};\n\nclass Model : public INotify\n{\npublic:\n\tint gridid;\n\tfloat x;\n\tfloat y;\n\tfloat z;\nprotected:\n\tbool selected;\npublic:\n\tbool getSelected() { return this-&gt;selected; }\n\tvoid setSelected( bool v ) {\n\t\tif ( this-&gt;selected != v ) {\n\t\t\tthis-&gt;selected = v;\n\t\t\tonChanged( this );\n\t\t}\n\t}\t\t\npublic:\n\tModel( int id, float x, float y, float z ) {\n\t\tthis-&gt;gridid = id;\n\t\tthis-&gt;x = x;\n\t\tthis-&gt;y = y;\n\t\tthis-&gt;z = z;\n\t\tthis-&gt;selected = false;\n\t}\n};\n<\/pre>\n<p>\nModel \u30af\u30e9\u30b9\u306b\u306f\u3001__event \u30ad\u30fc\u30ef\u30fc\u30c9\u3092\u4ed8\u3051\u3066\u3001onChanged \u30a4\u30d9\u30f3\u30c8\u767b\u9332\u306e\u6e96\u5099\u3092\u3057\u3066\u304a\u304d\u307e\u3059\u3002selected \u30d7\u30ed\u30d1\u30c6\u30a3\u304c\u5909\u66f4\u306b\u306a\u3063\u305f\u3068\u304d\u306b\u3001onChanged \u3092\u547c\u3073\u51fa\u3057\u307e\u3059\u3002<br \/>\n\u3053\u306e\u6642\u70b9\u3067\u3001View \u3092\u5224\u65ad\u3055\u305b\u3066\u3082\u3088\u3044\u306e\u3067\u3059\u304c\u3001\u4f9d\u5b58\u95a2\u4fc2\u3068\u3044\u3057\u3066\u306f Model <- View \u304c\u671b\u307e\u3057\u3044\u306e\u3067\u3001\u3042\u3048\u3066\u3053\u3046\u3044\u3046\u5f62\u306b\u3057\u3066\u304a\u304d\u307e\u3059\u3002\n<\/p>\n<p>\n\u25a0Model \u304b\u3089\u306e\u901a\u77e5\u3092 View \u3067\u53d7\u3051\u308b\u3002\n<\/p>\n<p>\nModel \u3067 INotify::onChanged \u3092\u547c\u3073\u51fa\u3057\u305f\u3068\u304d\u306b\u306f\u3001ITagert::onPropertyChanged \u3092\u547c\u3073\u51fa\u3059\u3088\u3046\u306b\u3057\u307e\u3059\u3002<br \/>\nGridView, GraphicsView \u306e\u305d\u308c\u305e\u308c\u306b\u3001onPropertyChanged \u3092\u5b9f\u88c5\u3057\u3066\u304a\u304d\u307e\u3059\u3002\n<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nclass GridView : public ITarget\n{\npublic:\n\tModels *models;\npublic:\n\tvoid print() {\n\t\tif ( models == NULL ) return;\n\t\tfor ( auto it = models-&gt;begin(); it != models-&gt;end(); ++it ) {\n\t\t\tModel *m = *it;\n\t\t\tcout &lt;&lt; m-&gt;gridid &lt;&lt; &amp;quot;:&amp;quot; &lt;&lt; m-&gt;getSelected() &lt;&lt; endl;\n\t\t}\n\t}\n\tvoid onChecked( int row, bool selected ) {\n\t\tif ( models == NULL ) return ;\n\t\tfor ( auto it = models-&gt;begin(); it != models-&gt;end(); ++it ) {\n\t\t\tif ( row == 0 ) {\n\t\t\t\tModel *m = *it;\n\t\t\t\t\/\/ m-&gt;selected = selected;\n\t\t\t\tm-&gt;setSelected( selected );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\trow --;\n\t\t}\n\t}\n\tvoid onPropertyChanged( void *sender )\n\t{\n\t\tauto model = (Model*)sender;\n\t\tcout &lt;&lt; &amp;quot;GridView::onChanged: &amp;quot; &lt;&lt; model-&gt;gridid &lt;&lt; endl;\t\n\t}\n};\n\nclass GraphicsView : public ITarget\n{\npublic:\n\tModels *models;\npublic:\n\tvoid print() {\n\t\tif ( models == NULL ) return;\n\t\tfor ( auto it = models-&gt;begin(); it != models-&gt;end(); ++it ) {\n\t\t\tModel *m = *it;\n\t\t\tcout &lt;&lt; m-&gt;gridid &lt;&lt; &amp;quot;:&amp;quot; &lt;&lt; m-&gt;getSelected() &lt;&lt; endl;\n\t\t}\n\t}\n\tvoid onClick( int gridid ) {\n\t\tif ( models == NULL ) return ;\n\t\tfor ( auto it = models-&gt;begin(); it != models-&gt;end(); ++it ) {\n\t\t\tModel *m = *it;\n\t\t\tif ( m-&gt;gridid == gridid ) {\n\t\t\t\t\/\/ m-&gt;selected = !m-&gt;selected;\n\t\t\t\tm-&gt;setSelected( !m-&gt;getSelected() );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tvoid onPropertyChanged( void *sender )\n\t{\n\t\tauto model = (Model*)sender;\n\t\tcout &lt;&lt; &amp;quot;GraphicsView::onChanged: &amp;quot; &lt;&lt; model-&gt;gridid &lt;&lt; endl;\t\n\t}\n};\n<\/pre>\n<p>\n\u25a0\u30d0\u30a4\u30f3\u30c9\u3059\u308b\n<\/p>\n<p>\n__hook \u30ad\u30fc\u30ef\u30fc\u30c9\u3092\u4f7f\u3063\u3066\u3001Model::onChanged \u3068\u3001GridView::onPropertyChanged \u3092\u30d0\u30a4\u30f3\u30c9\u3057\u3066\u3044\u304d\u307e\u3059\u3002<br \/>\nModel \u306e\u901a\u77e5\u5148\u306f\u30012 \u306e View \u306b\u306a\u308b\u306e\u3067\u3001__hook \u3092 2\u56de\u5b9a\u7fa9\u3057\u307e\u3059\u3002\n<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nint main()\n{\n\tmodels = new Models();\n\tgraphicsView = new GraphicsView();\n\tgridView = new GridView();\n\tgraphicsView-&gt;models = models;\n\tgridView-&gt;models = models;\n\n\tfor ( int i=0; i&lt;10; i++ ) {\n\t\tauto model = new Model(i,0.0,0.0,0.0);\n\t\t__hook( &amp;Model::onChanged, model, &amp;GridView::onPropertyChanged, gridView );\n\t\t__hook( &amp;Model::onChanged, model, &amp;GraphicsView::onPropertyChanged, graphicsView );\n\t\tmodels-&gt;push_back( model );\n\t}\n\tgraphicsView-&gt;onClick( 2 );\n\tgridView-&gt;print();\n\n\tgridView-&gt;onChecked( 8, true );\n\tgridView-&gt;print();\n}\n<\/pre>\n<p>\n\u3053\u3053\u3067\u306f\u3001Model \u306e selected \u30d7\u30ed\u30d1\u30c6\u30a3\u304b\u3089\u76f4\u63a5\u5909\u66f4\u901a\u77e5\u3092\u53d7\u3051\u308b\u305f\u3081\u306b\u3001\u3059\u3079\u3066\u306e model \u306b\u5bfe\u3057\u3066 onChanged \u3092\u767b\u9332\u3057\u307e\u3059\u3002<br \/>\n\u305f\u3060\u3001\u3053\u308c\u3060\u3068\u9762\u5012\u306a\u306e\u3067\u3001vector<Model*>::onChanged \u306b\u767b\u9332\u3057\u3066\u3001\u8907\u6570\u306e model \u3092\u4e00\u62ec\u306b\u6271\u3046\u3088\u3046\u306b\u3057\u305f\u3044\u3067\u3059\u3088\u306d\u3002\n<\/p>\n<p>\n\u25a0\u5b9f\u884c\u7d50\u679c\n<\/p>\n<p>\n\u5b9f\u884c\u7d50\u679c\u306f\u3053\u3093\u306a\u611f\u3058\u3067\u3059\u3002<br \/>\n\u6700\u521d\u306f\u3001GraphicsView -> Model -> GridView \u3078\u306e\u30c7\u30fc\u30bf\u4f1d\u64ad\u3002\u4e8c\u756a\u76ee\u306e\u3082\u306e\u306f\u3001GridView -> Model -> GraphicsView \u3067\u306e\u4f1d\u64ad\u3067\u3059\u306d\u3002\n<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nD:\\work\\blog\\src\\alice&gt;alice018\nGraphicsView::onChanged: 2\nGridView::onChanged: 2\n0:0\n1:0\n2:1\n3:0\n4:0\n5:0\n6:0\n7:0\n8:0\n9:0\nGraphicsView::onChanged: 8\nGridView::onChanged: 8\n0:0\n1:0\n2:1\n3:0\n4:0\n5:0\n6:0\n7:0\n8:1\n9:0\n<\/pre>\n<p>\n\u3042\u3048\u3066\u3001ViewModel, Controller \u3092\u4f7f\u308f\u305a\u306b\u66f8\u3044\u3066\u3044\u307e\u3059\u304c\u3001\u3053\u306e\u30d0\u30a4\u30f3\u30c9\u306e\u90e8\u5206\u306f ViewModel \u3068\u3057\u3066\u3082\u826f\u3044\u306f\u305a\u3067\u3059\u3002<br \/>\nModel::onChanged \u30a4\u30d9\u30f3\u30c8\u306b View \u306e\u578b\u304c\u5165\u3063\u3066\u3053\u306a\u3044\u306e\u3067\u3001\u3069\u3093\u306a View \u304c\u6765\u3066\u3082\uff08\u3042\u308b\u3044\u306f View \u304c\u306a\u304f\u3066\u3082\uff09 Model \u3092\u5909\u3048\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u305b\u3093\u3002<br \/>\n\u305d\u3046\u3044\u3046\u610f\u5473\u3067\u306f\u305d\u308c\u306a\u308a\u306b\u72ec\u7acb\u6027\u304c\u9ad8\u3044\u304b\u306a\u3068\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5177\u4f53\u7684\u306b\u8a00\u3048\u3070\u3001\u4ee5\u4e0b\u306e\u72b6\u6cc1\u3092\u5b9f\u73fe\u3055\u305b\u307e\u3059\u3002 \u25a0\u76ee\u7684 GridView \u3068 GraihpcsView \u306e 2\u3064\u306e View \u304c\u3042\u308b\u3002 GridView \u306e\u9805\u76ee\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u3068\u3001GraphicsView \u306e\u3042\u308b\u70b9\u304c\u53cd\u8ee2\u3059\u308b\u3002 &hellip; <a href=\"http:\/\/www.moonmile.net\/blog\/archives\/3575\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[22],"tags":[],"class_list":["post-3575","post","type-post","status-publish","format-standard","hentry","category-c"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/3575","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/comments?post=3575"}],"version-history":[{"count":1,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/3575\/revisions"}],"predecessor-version":[{"id":3576,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/3575\/revisions\/3576"}],"wp:attachment":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/media?parent=3575"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/categories?post=3575"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/tags?post=3575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}