Tuesday, January 31, 2017

Polymorphism, Abstract Classes and Interfaces

This week, the focus of our studies are polymorphism -- another pillar, if you will, along with inheritance and encapsulation, of object-oriented programming -- abstract classes and interfaces.

Inheritance allows for the defining of general classes, called superclasses, which can then be extended to a variety of specialized, instance-of subclasses.  Basically, the concept of polymorphism is when any one of those subtypes, belonging to the latter, subclass, can be passed into the superclass' methods or work with the superclass' variables.  Since the subtype is an instance of the supertype, (and not vice-versa), its many forms, created through subclasses, can each be used with it.  It's probably easiest to describe with an example, such as a geometric object superclass that has subtypes of circles or squares.  These might each have instances that could be passed into the superclass GeometricObject's methods, for example, maybe a color setter.  Or, their member properties could refer to the superclass' data definitions, such as one for color.  I think polymorphism can also refer to method overriding, where you have similar method definitions in each of the subtypes, but different executions in each version.

The abstract class cannot have any concrete  types, no instantiations, so it would never be called or implemented with the new object operator.  The purpose of the abstract class is to define these common features, and allow reuse and convenient interaction.  For example, a circle and square's overriden getArea method allows for an additional method of comparison of this data that was achieved through different calculations.

While an abstract superclass defines common behavior and features for connected, related subclasses, the interface defines behavior for any class, whether or not it's related to it.  Java provides some interfaces such as Comparable and Clonable, which a variety of other classes, whether pre-defined in the Java library or homemade, can implement.

Tuesday, January 17, 2017

OOP



OOP is not in all languages, and I have used some that follow the procedural paradigm, including JavaScript.   I've only used PHP5, which was updated for OOP.  Although, while Javascript was initially a functional language, it too is changing with ES6 (EcmaScript6).   If I am not mistaken, EcmaScript 4 does not have a true Object Oriented paradigm, although most of its constructs are objects.  I'm essentially doing procedural programming with these, when I'm not setting up classes and using the concepts of OOP.


What was your experience?

Most of my experience with Object Oriented thinking is from Java. Through that language, I learned of classes, which define the properties and behaviors of objects, as well as encapsulation and abstraction, where classes are separated and hidden from their descriptions, calling/driving or their use, as well as other concepts like inheritance, where multiple classes can pass down features. Overall, data and methods are coupled with objects; the objects are the focus, as well as operations performed on those objects.  This is in contrast to procedural programming, where methods are designed and the focus of execution.


How extensively have you used OOP outside of the classroom?

It's my goal to apply what I've learned when I code with other languages, such as Python. There is room for improvement for me, in this respect.


Are you experienced with UML diagrams and do they help?

I've encountered a type of UML diagram using SQL, but have never employed such to solve a programming challenge. Indeed, another goal of mine is to better plan my builds, using algorithms, and, yes, a UML diagram, perhaps, a class based one.


This week, the programming assignment, Casino, was a lot of fun.  I enjoy gaming.  It was a good refresher for a lot of the concepts I had studied in the past, and I enjoyed working with my team.

Tuesday, January 10, 2017

Java!

This semester, I am reunited with Java and the Eclipse IDE after a year-long break.  At Foothill College, I attended a three-part course series that covered object-oriented programming methodologies through advanced data structures and algorithms.  Everyone I spoke to seemed to agree that it was a rigorous, challenging and enjoyable series.

This time around, while at CSUMB, I will focus on picking up points that I missed the first time around, solidifying my understanding of the language and object-oriented programming in general, writing more elegant, neater code, better committing to memory the syntactical and semantic details of the language, so as to permit writing/programming without having to frequently refer to notes or a text, as well as more freely and correctly articulating what I've been learning.  Furthermore, I'd like to learn to code for Android.

Reviewing the text and notes of module 1, I am reminded of a lot, remarkably, for some examples, that strings are non-primitive data types/objects with a variety of useful methods like .length(), .toLowerCase or .indexOf().  I was also reminded of type coercion for ints defined as floats, but that the opposite is illegal, and of truncation that occurs when casting floats to int.  Thinking further about some of the code I've written in the past in terms of its being part of a library, for example, System or Scanner, with, for example, .out and .print as the formers' methods, my understanding had been a little more shallow with my simply using the code and not realizing where it fits in object-oriented programming in a broader way.  Lastly, public/private and static membership, and where to place variable's definitions, are all concepts I am reviewing.

There is a lot more to think about and review, and I am glad to be studying Java again because it's interesting and informative for programming, over all.  Since I am studying to become a software engineer, the structural precision and detail that Java requires is really conducive to learning object-oriented coding concepts and structure.  I've studied several high-level languages at this point, including JavaScript, Python and PHP, and am becoming more and more proficient.  How much so?  I must laugh and shake my head in disbelief every time someone asks me, 'you know that Java and JavaScript are unrelated, right?'  For God's sake, I should hope so!  Still, I am invariably humble, so would rank myself as intermediate in my skills, rightly or wrongly.  I mean, compared to whom.  Furthermore, I am slow, even if I can produce debugged, working programs.  As mentioned in the syllabus, some students will take two hours to complete an assignment, while, others, ten.  To this end, a good goal will be for me to increase my speed, too, during this semester.