In my last post, we started bringing together the pieces of our previous tutorials together – we were able to set up our IDEs, created packages, classes, variables and Identifiers. In this post, we will continue from where we stopped which was the ShapeVariableBean.java class. Looking again at the structure of our application (AreaofShapes) as we discussed earlier here, we have three packages, nine (9) classes and one (1) interface altogether as shown below.
In the last lesson, I explained the purpose of each package and we saw the content of ShapeVariableBean and how encapsulation came to play. Today, we will focus more on the com.bee.code.blog.ShapeController package and also, we will see how other classes implements interface within this package. In com.bee.code.blog.ShapeController package, the shapes are divided into two; PolygonController and NonpolygonController.
Note: As an update on the last post, I added a new item on this package which is what we will be focusing on today. I added interface AllShapesInterface above so we can see how to make use of an interface in the course of these set of lessons. Before we continue, please refer to my earlier post on interface where I explained in detail what an Interface is in case you missed the lesson.
Recently, one of my BCB readers asked me a question that brought about this blog topic, he said “I have read through your several posts but how do I bring them all together and write a complete functional code?” Then I thought to myself that he was right, probably other readers might also have the same challenge bringing all the pieces together. Therefore, in this post and my next couple of posts, we will be taking a deep dive, referring back at every topic on Java we have previously dealt with on this blog in order to write a complete functional code. I hope you are ready to get your hands really dirty…lol.
Assumption: To start with, I assume that by now you have installed Java and you have java path set properly on your machine. If not, please refer to my previous post on this Lay your Bed this Christmas. Remember to direct all questions to me should you have any challenge following the steps. I will be using Netbeans IDE (Integrated Development Environment) for this example, you can use any IDE you are comfortable with to run this example. See list of possible IDEs and where to download them on this post Lay your Bed this Christmas.
Task: We will be writing a sample program to calculate the area of different basic shapes i.e. rectangle, square, circle etc..
Abstraction:This is a process whereby important details of a method are hidden and only the functionality is shown to the user. For instance, Abstraction will only tell the user things like a class can cook, wash, and fly by listing out the functions but not how the actual cooking, washing and flying are done. In Java, the ‘what a class can do’ is known as method while the ‘how the method does them’ is called Implementation. Therefore we can simply say abstraction list methods and hides implementation.
Over the last couple of weeks, we have looked at Java Modifiers and Basic Java Keywords and syntax I and II. As you may already know, Java is an object oriented program (OOP). OOP (Object Oriented Programming) as a programming model involves the collection of interacting objects. An Object is a black box which contains code and data, it sends and receives messages and are used to represent real life concepts ranging from human beings (described by name, address, and so forth) to countries (whose properties can be described and managed) down to the little widgets on a computer desktop (such as buttons and scroll bars). Some of the concepts of OOP have been discussed in my earlier posts however, despite these discussions OOP will be incomplete without explaining the following concepts: