{"id":88,"date":"2021-03-31T03:37:48","date_gmt":"2021-03-31T03:37:48","guid":{"rendered":"http:\/\/jonathanlimpus.com\/wordpress\/?p=88"},"modified":"2021-03-31T03:37:48","modified_gmt":"2021-03-31T03:37:48","slug":"cst-338-week-4-learning-journal","status":"publish","type":"post","link":"http:\/\/jonathanlimpus.com\/wordpress\/index.php\/2021\/03\/31\/cst-338-week-4-learning-journal\/","title":{"rendered":"CST 338 &#8211; Week 4 Learning Journal"},"content":{"rendered":"\n<h3>Polymorphism<\/h3>\n\n\n\n<p>An example of polymorphism that I often see is the &#8220;Shapes&#8221; class. I used this example in an introductory Java course previously. A class <code>Shapes<\/code> is defined as: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public abstract class Shapes {\nprotected double xPos, yPos, zPos, scale;\n\npublic Shapes() {\n\n    xPos = 0.0;\n    yPos = 0.0;\n    zPos = 0.0;\n    scale = 0.0;\n}\n\/\/ ...<\/code><\/pre>\n\n\n\n<p>This creates a class with all the common factors of a geometrical shapes. Then, in child classes <code>Box<\/code> and <code>Sphere<\/code>, all of the methods and data specific for that shape are given:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class Box extends Shapes {\n\tprivate double height, width, depth, volume;\n\t\n\tpublic Box() {\n\t\t\/\/This is the default constructor for Box\n\t\tsuper();\n\t\theight = 0.0;\n\t\twidth = 0.0;\n\t\tdepth = 0.0;\n\t\tcalculateVolume(); \n\t}\n        \/\/...\n\t<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>public class Sphere extends Shapes {\n\tdouble radius, volume;\n\t\n\tpublic Sphere() {\n\t\tsuper();\n\t\tradius = 0.0;\n\t\tcalculateVolume();\n\t}\n        \/\/...\n\t<\/code><\/pre>\n\n\n\n<p>This allows use to use <code>Shapes<\/code> methods and data (such as methods that modify their position on the Cartesian plane) on the Sphere and Box objects without having to define them in each class. <\/p>\n\n\n\n<h4>Abstract Classes vs. Interfaces<\/h4>\n\n\n\n<p>When I was learning Java in my community college courses and I was first introduced to interfaces, my first thought was &#8220;Oh, this is just abstract classes from C++&#8221;. It wasn&#8217;t until later that I actually realized that this is not actually the case, but that Java actually supports abstract classes AND interfaces. <\/p>\n\n\n\n<p>Both abstract classes and interfaces cannot be instantiated and contain abstract methods. However, interfaces only contain undefined classes that do not contain any substance. Abstract classes, however, can contain data and some methods, as seen in the <code>Shapes<\/code> method above. The way that makes most sense to me is to say that interfaces are more strictly abstract in nature. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Polymorphism An example of polymorphism that I often see is the &#8220;Shapes&#8221; class. I used this example in an introductory Java course previously. A class Shapes is defined as: This creates a class with all the common factors of a geometrical shapes. Then, in child classes Box and Sphere, all of the methods and data &#8230; <a title=\"CST 338 &#8211; Week 4 Learning Journal\" class=\"read-more\" href=\"http:\/\/jonathanlimpus.com\/wordpress\/index.php\/2021\/03\/31\/cst-338-week-4-learning-journal\/\" aria-label=\"More on CST 338 &#8211; Week 4 Learning Journal\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8,7],"tags":[],"_links":{"self":[{"href":"http:\/\/jonathanlimpus.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/88"}],"collection":[{"href":"http:\/\/jonathanlimpus.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/jonathanlimpus.com\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/jonathanlimpus.com\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/jonathanlimpus.com\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=88"}],"version-history":[{"count":3,"href":"http:\/\/jonathanlimpus.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/88\/revisions"}],"predecessor-version":[{"id":91,"href":"http:\/\/jonathanlimpus.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/88\/revisions\/91"}],"wp:attachment":[{"href":"http:\/\/jonathanlimpus.com\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=88"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/jonathanlimpus.com\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=88"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/jonathanlimpus.com\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=88"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}