Polymorphism
Polymorphism in Java deals with the concept of "late binding." Late binding allows objects to be assigned the proper method definitions after compile time. This is important because inherited objects may need to override a method from an ancestor class. If the parent method was bound at compile time, derived objects would be unable to override it. The Java runtime determines if a derived object needs to use its own version of a method and binds that version to the object, allowing polymorphism to occur. Polymorphism allows a derived class to inherit the properties and methods of its ancestor classes while retaining the ability to morph those methods for its own purposes.
A quick example of polymorphism would be if you created a Ball class with the basic properties and functions of a ball, such as color, size, and move(), and then you used the Ball class as a base class for different kinds of ball classes, like Basketball, Baseball, Bowlingball, etc. Each type of ball inherits the basic properties of the Ball class, but their move() methods are all different. A basic ball's move() method may simply be to roll, which works for Bowlingball(), but a basketball's move() method requires it to bounce, and a baseball's move() method requires it to be pitched. Polymorphism allows each derived ball class to modify the inherited move() method for its own specific purpose. Furthermore, a programmer can conveniently store different kinds of balls in the same Ball[] array since they are all derived from the same Ball class.
Abstract Classes & Interfaces
An interface can be thought of like a blueprint for a class. Methods are declared in an interface but not defined. Interfaces work as a guide for programmers to create a working class. For example, a Map interface would declare all methods required for a derived class to actually be a "Map." The derived class must define all methods declared in the interface. Any programmer who uses the Map interface can be confident that their derived program has the minimum functionality of a map because they based it on a blueprint.
An abstract class is similar to an interface but can be thought of as more of a skeleton than a blueprint. It is not a complete (concrete) class and cannot be instantiated on its own. It must be extended by another class. Abstract classes contain abstract methods which are left undefined. These methods are meant to be defined by an implementing class. Unlike an interface, however, abstract classes are able to define other methods. For instance, abstract classes can implement interfaces.
Keeping Up
This week was less stressful for me than last week because I was not the project manager. I was able to just focus on my part of the assignment while still being available to help my teammates if requested. Our barcode scanner seemed to come together easily, despite having a couple of tricky parts. I am still learning how to collaborate with others. It can be hard for me not to just fix code myself if the errors are trivial. Sometimes it does make more sense given the limited time we have, but I need to also be respectful of my teammates' boundaries.
No comments:
Post a Comment