Tuesday, July 29, 2008

Encapsulation in OOP

Level: Basic

Two of the main features of the Object-Oriented Programming (OOP) paradigm is flexibility and maintainability. It is so desirable for one's source code to be flexible in spite of changes in its internal implementations. Programmers don't have to worry about their codes getting broken due to changes in the implementation of the Application Programming Interfaces (API) that they are using. All they have to know is that public methods of a given API behave the way they know it should regardless of its implementation details. Through this sense of flexibility in one's code, users of such API are guaranteed that their own code will behave accordingly for a very long time. This advantage is offered by OOP through encapsulation. Encapsulation hides the implementation details of an API to accomodate maintainability and flexibility in its use. It serves as a protection for a class's attributes by forcing client users of the class to access its protected attributes through publicly accessible methods or behaviors.
An example implementation of encapsulation in class would be the following (using the Java programming language):

public class Person {
private String name;
private String age;

public void setName(String name){
this.name = name;
}
public String getName(){
return this.name;
}

public void setAge(int age){
this.age = age;
}
public int getAge(){
return this.age;
}
}


Notice that class Person's attributes are declared as private to protect them from being accessed directly outside Person. Instead, they are accessed through what we call setters (setName,setAge) and getters (getName, getAge). Clients of this class will have to use setters to set the value of its attributes and getters to determine the value of its attributes. By doing so, we will not be able to see others codes accessing Person's name and age as follows:

public class Tester {
void testPerson(){
Person person = new Person();
person.name = "Juan dela Cruz";
person.age = 20;
}
}


Instead, Tester will class will use Person class as follows:

public class Tester {

void testPerson(){

Person person = new Person();

person.setName"Juan dela Cruz");

person.setAge(20);

}

}


Also, since Tester class accesses Person's age through Person's setAge setter, we could be sure that Person's age will not have 0 or any negative value by adding a checker into Person's setAge method like the following:

//preceeding code removed
public void setAge(int age) throws
IllegalAgeValueException{
if (age > 0) {
this.age = age;
} else {
throw new IllegalAgeValueException(); //in which
IllegalAgeValueException is a //custom exception
}
}


Encapsulation in OOP leverages an API's maintainability and flexibility if used properly. Of course it doesn't mean that since OOP offers encapsulation the programmer does not have to do anything in order to take advantage of such feature. In order to do so, one has to write his code in an encapsulated manner. :]

Continually learning,
Jep

Monday, July 28, 2008

Back to the Basics

It has been a few weeks now since I started reviewing my Java basics. There are so many trivial matters about programming that I seem not to pay attention to just because they are, as I said, trivial. One example would be optimization. Due to busyness and all the rush, I seldom check my code if it runs the optimized way. If it works, then it works. But an excellent programmer should not treat his code as so. A programmer's code is his essence. Show me your code and I'll tell you what kind of programmer you are. I am just so thankful to God that He made me see this weakness of mine at this early stage of my software development career. Optimization is just one of those programming weaknesses of mine. There are still lots of them and I am hoping to realize them as I go back to my Java basics and then see what action plans I could come up with to improve on those areas. :]

Friday, July 25, 2008

PicLens : Redifining FireFox Experience

While I was searching for a really cool add-on that I could plug into my FireFox browser, I came accross this one called PicLens. It gives the user a far better net-surfing experience by making image and video searches a lot more interactive and enjoyable. It has something what they call as "The Wall" which is a 3-D interface to one's search results. It feels like picking one's choice from a wall of images and videos. Videos could be watched on the wall by clicking on it, which means users don't have to go out of the wall and go to the video's main page just to watch it. This gives the user more convenience in searching for the media that they are interested with. I give it a 9 out of 10 points, the 1 point less is for the fact that it does not run linux machines..hehe :] For more information about this cool add-on, just visit the site http://www.piclens.com/ and enjoy a better and much cooler FireFox :]

Thursday, July 17, 2008

NASA Mars Lander's Robotic Arm shuts down to save its self

Yesterday I read an article from PC World about NASA Mars Lander's robotic arm shutting down its self to avoid getting hurt which would make its situation worse.
The Mars Lander found its self on a very crucial situation during execution of its mission. After receiving commands from NASA's command center, the robotic arm decided to shutdown its self instead of compromising and getting its wrist into a bad shape. Further details of the story can be found in this link: http://www.pcworld.idg.com.au/index.php/id;593684490 .
I just get so excited whenever I get to read news such as this. It has always been a dream of mine to be a robotics engineer. I get so amazed by how a robot could execute the commands given to it by its developer. So far I don't have yet a comprehensive plan on how I am going to pursue this dream of mine. Still, I believe there is always a time for everything under the sun. (Ecclesiastes 3:1) :]
If there is anyone out there who could help me on this, please do kindly lend me a hand by sharing your knowledge. I would greatly appreciate it :]

Continually learning,
Jep


The Joy of Helping Others

In spite of the heavy workload that I have been juggling this week, by God's grace, He enabled me to help other people in our office in some way or another. To help other people and see them get relieved somehow with the stress that they are carrying on their shoulders is a joy for me. To see someone smile in spite of being tired relieves me of my own tiredness. By God's enabling I would love to continually help other people with the hope that someday our world, starting from my office, would get to learn the true spirit of volunteerism, offering their selves for the benefit of the people around them.

2 Corinthians 9:8
And God is able to make all grace abound to you, so that in all things at all times, having all that you need, you will abound in every good work.


Continually learning,
Jep

Tuesday, July 15, 2008

Now Really Learning EJB

For the past three years of working here at ASTI-DOST I and my team mates have been building various web applications, most of which are information systems. Our first main project wasn't that really big so we opted to implement it using just POJOS, Servlets, and JSPs with three layer MVC as framework. Same with the following projects, they weren't really that complicated to require the use of EJBs. Until January this year, we started on a totally massive project that encompasses a lot of agencies and councils under the department of science, both with existing information systems and those who don't have yet. The whole system will be covering a lot of components that it will require a really sturdy and robust web application framework to make it last for a lot of years, easily maintanable and expandable in the future. Now I could see that at last I will be able put into practice my EJB knowledge into a real world problem, a really big problem I should say. Still, there are other application frameworks that comes into the scene that could match up to EJB. . .like Spring. In fact, I have already studied and practiced Spring into a mini project of mine before even trying out EJB. But the fact that I have already used Spring and saw its promises against EJB gives me the joy of studying EJB 1.4 and see what Spring is talking about. Now that I could see the flaws of EJB 1.4 in contrast to Spring, I could understand more why Spring did this and did that in response to EJB's shortcomings. On my study plan, after learning EJB 1.4 and putting it into practice (oh what a tedious task. . .), I will dive into EJB 3.0 to see what was EJB's response to Spring. I am pretty sure both will really battle well and I am more than excited to learn both.

Ever learning,
Jep

Sunday, July 13, 2008

The Irony of Being a Iskolar ng Bayan

As I posted last week, I was supposed to go to Thailand for a coordination meeting with other ASEAN countries regarding distance learning or e-Learning. Last friday I was at the Department of Foreign Affairs to fix my passport. To my shock and dismay (not really dismay...), DFA won't issue me a passport unless I get a clearance from DOST that they are allowing me to travel outside the Philippines for four glorious days. That sounds just fine but the catch is DOST won't issue me a clearance to travel unless an authority issues a guarantors letter noting that I am going to come back here in the Philippines after four days. The problem is that there is no one, an authority, that would guarantee that for DOST. Hehe, what an irony, I am a scholar of the Philippines and its government and yet I can't travel for a scholarly meeting outside my country. Well, it doesn't really bother me that much since I know God must have a reason why it'd happen. Hehe, can't wait for the lifting of my ban to travel outside the borders of my beloved country, just one more year. :]

Continually learning,
Jep

Possible New Pet Project :]

Hehehe! Just this morning I had a meeting with my boss and some of my co-team-leaders. They presented to me a proposal about a possible project of one of the government's departments. I got excited about it because the completion of this project will bring a big impact to many sectors of the society, specially for the tourism industry. Now, it's up to me to decide if we would accommodate the project given the work loads I am carrying right now. Whew! I could say that it is pretty tough to decide now since I would really love to see the project go into completion for the benefit of my fellow Filipinos and the other nationalities as well. Well, I still got a few hours to think about it. :]

Continually learning,
Jep

Thursday, July 10, 2008

Passport Craze

Just yesterday my boss emailed me regarding a coordination meeting regarding e-Learning to be held at a not so distant country from hours. Yep, I got excited about it until I got to realize that I don't have a passport yet, nyahaha. Panic filled my mind. Blood rushed to my head. I now only have almost 4 days to have a passport and I don't really know what is going to happen. waaah! Still I'm hoping to get one. If ever, this will be my first travel outside the Philippines. yay! :]

Learning Java Mobile Edition

This afternoon one of my college batch mates asked me if I want to learn Java Mobile Edition and I immediately said yes. For the past three years of working I have been much involved with web application development, like information systems. Now I am working on a considerably big scale information system with three years allotted for development and implementation. So I have so little idea on what I'll be learning about JME. I am excited about it and now thinking on how we will start our online class. We still have no curriculum and reading materials for the class and we are looking for people who want to join us. For those want to join the group, please send me your email so I could send you an invitation. We hope to have more people on the group before we start the class.


Continually learning,
Jep