{"id":791,"date":"2020-07-04T22:07:00","date_gmt":"2020-07-05T04:07:00","guid":{"rendered":"https:\/\/www.great-white-software.com\/blog\/?p=791"},"modified":"2020-07-01T23:01:13","modified_gmt":"2020-07-02T05:01:13","slug":"class-vs-module","status":"publish","type":"post","link":"https:\/\/www.great-white-software.com\/blog\/2020\/07\/04\/class-vs-module\/","title":{"rendered":"Class vs Module"},"content":{"rendered":"\n<p>Should be a great WWE match up <\/p>\n\n\n\n<p>Really the question was &#8220;should I use a class or a module?&#8221;<\/p>\n\n\n\n<p>There&#8217;s not really  global &#8220;Oh always use X&#8221; answer here.<\/p>\n\n\n\n<p>But usually if you find yourself wiring code that passed data to a method and you have a group of methods that collectively define a &#8220;data type&#8221; then you probably want a class.<\/p>\n\n\n\n<p>What do I mean by that ?<\/p>\n\n\n\n<p>Suppose you create a structure and put it in a module. And then that module has all kinds of methods that perform some kind of operations on that structure. That really probably _should_ be a class and all the methods in that module methods in the class.<\/p>\n\n\n\n<p>Modules, or namespaces, arent as a mechanism to define a data type. This kind of style is very classical non-OOP design. <\/p>\n\n\n\n<p>There _may_ still be reasons you want to use this style though. Yoi might use it when the data you&#8217;re dealing with is used for a declare or other external API and so your choices ARE limited by what declares can accept. There _may_ be other ways to deal with this situation but it wouldn&#8217;t be the worst choice to use a namespace in such a case.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Should be a great WWE match up Really the question was &#8220;should I use a class or a module?&#8221; There&#8217;s not really global &#8220;Oh always use X&#8221; answer here. But usually if you find yourself wiring code that passed data to a method and you have a group of methods that collectively define a &#8220;data &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.great-white-software.com\/blog\/2020\/07\/04\/class-vs-module\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Class vs Module&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-791","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/791","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/comments?post=791"}],"version-history":[{"count":1,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/791\/revisions"}],"predecessor-version":[{"id":792,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/791\/revisions\/792"}],"wp:attachment":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/media?parent=791"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/categories?post=791"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/tags?post=791"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}