{"id":8872,"date":"2015-02-02T06:08:56","date_gmt":"2015-02-02T06:08:56","guid":{"rendered":"http:\/\/2slick.com\/web\/?p=8872"},"modified":"2015-02-04T04:10:07","modified_gmt":"2015-02-04T04:10:07","slug":"basic-steps-toward-ood-object-oriented-design","status":"publish","type":"post","link":"https:\/\/2slick.com\/web\/basic-steps-toward-ood-object-oriented-design\/affordablewebsitestips\/tutorials","title":{"rendered":"Basic steps toward OOD Object Oriented Design"},"content":{"rendered":"<p>In this tutorial I will go through some useful steps toward creating an OOD(Object Oriented Design) for a program(mobile game app). OOD only applies to an OOP(Object Oriented Program). You can also search the web for UML(unified modeling language) tools.<\/p>\n<p>Create a 'use cases' (UML):<\/p>\n<p>A game where you <span style=\"text-decoration: underline;\">start<\/span> by killing <span style=\"text-decoration: underline;\">enemies<\/span>. After all the <span style=\"text-decoration: underline;\">enemies<\/span> are dead, you then rescue the <span style=\"text-decoration: underline;\">princess<\/span> and <span style=\"text-decoration: underline;\">win<\/span> the game. If the <span style=\"text-decoration: underline;\">enemies<\/span> kill you then you <span style=\"text-decoration: underline;\">lose<\/span> the game and you have to restart.<\/p>\n<h3>Create a 'noun list':<\/h3>\n<p>Create a list of nouns(underlined above) that makeup your program. &nbsp;Erase duplicates. This is to develop a vague concept of the program.<\/p>\n<ul>\n<li>actor(player)<\/li>\n<li>enemies<\/li>\n<li>princess<\/li>\n<li>start menu<\/li>\n<li>win menu<\/li>\n<li>lose menu<\/li>\n<li>play button<\/li>\n<\/ul>\n<h3>Create 'Conceptual Object Model' or 'Conceptual Diagram':<\/h3>\n<p>Put the nouns into boxes and draw lines and describe the lines to indicate associations between the objects.This is to develop a vague concept of the program.<\/p>\n<p><a href=\"http:\/\/2slick.com\/web\/wp-content\/uploads\/2015\/02\/conceptual_object_model7.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8902\" title=\"conceptual_object_model\" src=\"http:\/\/2slick.com\/web\/wp-content\/uploads\/2015\/02\/conceptual_object_model7.jpg\" alt=\"\" width=\"441\" height=\"589\" srcset=\"https:\/\/2slick.com\/web\/wp-content\/uploads\/2015\/02\/conceptual_object_model7.jpg 441w, https:\/\/2slick.com\/web\/wp-content\/uploads\/2015\/02\/conceptual_object_model7-224x300.jpg 224w\" sizes=\"auto, (max-width: 441px) 100vw, 441px\" \/><\/a><\/p>\n<h3>Assign Responsibilities<\/h3>\n<p>Move the actions under the potential classes that will be responsible for them.<\/p>\n<p><a href=\"http:\/\/2slick.com\/web\/wp-content\/uploads\/2015\/02\/assign_responsibilities.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8909\" title=\"assign_responsibilities\" src=\"http:\/\/2slick.com\/web\/wp-content\/uploads\/2015\/02\/assign_responsibilities.jpg\" alt=\"\" width=\"441\" height=\"589\" srcset=\"https:\/\/2slick.com\/web\/wp-content\/uploads\/2015\/02\/assign_responsibilities.jpg 441w, https:\/\/2slick.com\/web\/wp-content\/uploads\/2015\/02\/assign_responsibilities-224x300.jpg 224w\" sizes=\"auto, (max-width: 441px) 100vw, 441px\" \/><\/a><\/p>\n<h3>Create your list of UML class diagrams<\/h3>\n<p>Create your list of class diagrams. Each class diagram will follow this basic structure.<\/p>\n<p><a href=\"http:\/\/2slick.com\/web\/wp-content\/uploads\/2015\/02\/clas_diagram.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8912\" title=\"clas_diagram\" src=\"http:\/\/2slick.com\/web\/wp-content\/uploads\/2015\/02\/clas_diagram.jpg\" alt=\"\" width=\"435\" height=\"353\" srcset=\"https:\/\/2slick.com\/web\/wp-content\/uploads\/2015\/02\/clas_diagram.jpg 435w, https:\/\/2slick.com\/web\/wp-content\/uploads\/2015\/02\/clas_diagram-300x243.jpg 300w\" sizes=\"auto, (max-width: 435px) 100vw, 435px\" \/><\/a><\/p>\n<p>Here is an actual class diagram of class player. I went ahead and added a 'die' property and associated method to the player class. Static properties or methods are represented as underlined in class diagrams.<\/p>\n<p><a href=\"http:\/\/2slick.com\/web\/wp-content\/uploads\/2015\/02\/class_diagram_player1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8916\" title=\"class_diagram_player\" src=\"http:\/\/2slick.com\/web\/wp-content\/uploads\/2015\/02\/class_diagram_player1.jpg\" alt=\"\" width=\"397\" height=\"256\" srcset=\"https:\/\/2slick.com\/web\/wp-content\/uploads\/2015\/02\/class_diagram_player1.jpg 397w, https:\/\/2slick.com\/web\/wp-content\/uploads\/2015\/02\/class_diagram_player1-300x193.jpg 300w\" sizes=\"auto, (max-width: 397px) 100vw, 397px\" \/><\/a><\/p>\n<h3>Interfaces in class diagrams<\/h3>\n<p>A dotted lined hollow arrow indicates that a class implements an interface. A solid lined hollow arrow indicates that a subclass inherits from that superclass.<\/p>\n<p>&nbsp;<a href=\"http:\/\/2slick.com\/web\/wp-content\/uploads\/2015\/02\/arrows_interface1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8921\" title=\"arrows_interface1\" src=\"http:\/\/2slick.com\/web\/wp-content\/uploads\/2015\/02\/arrows_interface1.jpg\" alt=\"\" width=\"341\" height=\"539\" srcset=\"https:\/\/2slick.com\/web\/wp-content\/uploads\/2015\/02\/arrows_interface1.jpg 341w, https:\/\/2slick.com\/web\/wp-content\/uploads\/2015\/02\/arrows_interface1-189x300.jpg 189w\" sizes=\"auto, (max-width: 341px) 100vw, 341px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/2slick.com\/web\/wp-content\/uploads\/2015\/02\/composition_agregation1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8925\" title=\"composition_agregation\" src=\"http:\/\/2slick.com\/web\/wp-content\/uploads\/2015\/02\/composition_agregation1.jpg\" alt=\"\" width=\"438\" height=\"305\" srcset=\"https:\/\/2slick.com\/web\/wp-content\/uploads\/2015\/02\/composition_agregation1.jpg 438w, https:\/\/2slick.com\/web\/wp-content\/uploads\/2015\/02\/composition_agregation1-300x208.jpg 300w\" sizes=\"auto, (max-width: 438px) 100vw, 438px\" \/><\/a><\/p>\n<p>The open diamond solid arrow indicates that an object is associated with another object, but it won't be destroyed if the object it's associated with it is destroyed (aggregation. A solid diamond arrow indicates that an object is associated with another object, but that it is dependent on that object and will be destroyed when that object is destroyed (composition).&nbsp;<\/p>\n<p>The above diagrams are structural diagrams or static diagrams. Although very useful, they don't show the process of the program. To show the process of the program you can use a 'sequence diagram'. Sequence diagrams can't realistically show the entire program all at once, just portions or certain scenarios.<\/p>\n<h3>Sequence Diagram<\/h3>\n<p>Here is an example sequence diagram, but it doesn't apply to our game example.<\/p>\n<p><a href=\"http:\/\/2slick.com\/web\/wp-content\/uploads\/2015\/02\/sequince_diagram_example.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-8929\" title=\"sequince_diagram_example\" src=\"http:\/\/2slick.com\/web\/wp-content\/uploads\/2015\/02\/sequince_diagram_example.jpg\" alt=\"\" width=\"650\" height=\"309\" \/><\/a>&nbsp;<\/p>\n<h3>S.O.L.I.D. Principles of object-oriented design<\/h3>\n<p>'SOLID' a useful checklist to consider while doing object oriented design.<\/p>\n<ol>\n<li><span style=\"font-size: 13px;\"><strong>S.<\/strong> Single Responsibility Principle - &nbsp;Create objects for 1 purpose. Don't combine multiple objects into 1 object (god objects). Objects should be responsible for itself.<\/span><\/li>\n<li><span style=\"font-size: 13px;\"><strong>O.<\/strong> Open \/ Close Principle - Open for extension, but closed for modification. If you need to modify expand on a program, don't modify old classes, objects or functions; instead create new objects or classes in addition to the old code.<\/span><\/li>\n<li><strong>L.<\/strong> Liskov Substitution Principle - Subclasses should be able to be treated like their super class.<\/li>\n<li><strong>I.<\/strong> Interface Segregation Principle - Interfaces shouldn't have too many signatures; if it does then those signatures should be split up into multiple interfaces. Classes can implement multiple interfaces.<\/li>\n<li><strong>D.<\/strong> Dependency Inversion Principle - It's often more intuitive or logical to create subclasses of abstract classes rather than subclasses of concrete classes. Example: a subclass 'blueJ' of super class 'robin', isn't intuituve. Instead there should be a third abstract class called 'bird' that classes 'blueJ' and 'robin' inherit from.<\/li>\n<\/ol>\n<h3>G.R.A.S.P.<\/h3>\n<p>General, Responsibility, Assignment, Software, Patterns.<\/p>\n<ol>\n<li><strong>Creator<\/strong> - Determining which objects should be responsible for creating other objects. Does one object contain, very closely use, or know about another object? If so it should be the object to create the other object.<\/li>\n<li><strong>Controller<\/strong> - Instead of linking a UI object directly to the application main objects, it's better to use a controlling between the two.<\/li>\n<li><strong>Pure Fabrication<\/strong>&nbsp;- This is a class that's roll is for pure functionality of the program. Sometimes concept models don't account for a realistic functioning program. Sometimes additional, purely functional classes are needed.<\/li>\n<li><strong>Information Expert<\/strong> -&nbsp;Assign responsibility to the class that has the most information needed to fulfill it. Example: containing data regarding the number of orders should be in the 'shoppingcart' class rather than the 'customer' class of the 'item' class.<\/li>\n<li><strong>High Cohesion<\/strong>&nbsp;- When an object's behaviors are related to its single responsibility. 'Low cohesion' means the opposite like in a 'god object'.<\/li>\n<li><strong>Indirection<\/strong>&nbsp;- Sometimes there's no getting around many objects that need to communicate with one another. This can lead to 'high coupling'. Instead create a new object to mediate or simplify communication between these objects.<\/li>\n<li><strong>Low Coupling<\/strong>&nbsp;- A coupling is a dependency i.e. a subclass is dependent on it's superclass. Low coupling means that an object has the least amount of dependencies as possible while still functioning.<\/li>\n<li><strong>Polymorphism<\/strong>&nbsp;- The ability for a class to function with different subclasses.<\/li>\n<li><strong>Protected variations<\/strong>&nbsp;- 'Encapsulation' and 'data hiding' do this. the consept 'Open \/ Close Principle' &amp; 'Liskov Substitution Principle'&nbsp;from the S.O.L.I.D. checklist do this.&nbsp;Protecting variations is basically the goal of changing a program as needed with the least amount of change and risk possible.<\/li>\n<\/ol>\n<h3>A.E.I.P.<\/h3>\n<p>Also known as 'apie'. Concepts for good object oriented programming.<\/p>\n<ol>\n<li><strong>A.<\/strong> Abstraction - Grouping your code into sections, like classes, objects &amp; APIs where the complex processing is happening 'behind the scenes' and all that you need to know or all that communicating objects need to know are a small number of input or output variables.<\/li>\n<li><strong>E.<\/strong> Encapsulation - Hides internal details of one object from another.<\/li>\n<li><strong>I.<\/strong> Inheritance -&nbsp;Instead of rewriting code, have classes inherit from super classes. This means your program will require less code and be easier to add onto or update.<\/li>\n<li><strong>P.<\/strong> Polymorphism - The ability of one object to be generic and used in many different ways. taking a different form is called polymorphism.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial I will go through some useful steps toward creating an OOD(Object Oriented Design) for a program(mobile game app). OOD only applies to an OOP(Object Oriented Program). You can also search the web for UML(unified modeling language) tools. Create a &#8216;use cases&#8217; (UML): A game where you start by killing enemies. After all [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[744,734,754,687,753],"class_list":["post-8872","post","type-post","status-publish","format-standard","hentry","category-tutorials","tag-app","tag-as3","tag-game","tag-mobile","tag-programing"],"_links":{"self":[{"href":"https:\/\/2slick.com\/web\/wp-json\/wp\/v2\/posts\/8872","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/2slick.com\/web\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/2slick.com\/web\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/2slick.com\/web\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/2slick.com\/web\/wp-json\/wp\/v2\/comments?post=8872"}],"version-history":[{"count":65,"href":"https:\/\/2slick.com\/web\/wp-json\/wp\/v2\/posts\/8872\/revisions"}],"predecessor-version":[{"id":8956,"href":"https:\/\/2slick.com\/web\/wp-json\/wp\/v2\/posts\/8872\/revisions\/8956"}],"wp:attachment":[{"href":"https:\/\/2slick.com\/web\/wp-json\/wp\/v2\/media?parent=8872"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/2slick.com\/web\/wp-json\/wp\/v2\/categories?post=8872"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/2slick.com\/web\/wp-json\/wp\/v2\/tags?post=8872"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}