Saturday 21 February 2009

Inheritance

As long as i keep writing this blog, i will say, I'm learning something new. Wow, so now i can count the days too when i'm in hibernation mode!! :D

I have started learning Java just few days back. I had heard that Java is slow. But that doesn't mean you should also be slow in learning, Pranali. :D

So, my topic is Inheritance today.

After reading inheritance from a highly recommended book of C++ (recommended by professors, by almost everyone i had met), I read it in Head First Java. I had never heard about this book, before coming in amdocs. So fast I am!! :D

I was aware of the biological definition of Inheritance.
As many OO concepts can be given analogies of the real world non-technical concepts, I used the same attitude while reading from the highly recommended book, but in rigid manner.
My Perception was -
1)We can inherit some class as children inherit from their parents.
2)There are few types of inheritance. Single , multiple etc.
3)If i want some feature in my class which is already present somewhere in other class, I will extend that class.
4)And yes, i knew one more thing - Inheritance is called Reusabilty too.

So i was aware of things in rigid manner. I never developed an insight for this concept. I don't even remember whether i had tried to develop that too. :(

After reading that highly recommended book around 3 times, I was very confident that i know OO, i know inheritance. But how wrong i was!! (This was the reason why i couldn't think of inheritance when i had done my first assignment in amdocs. )

In the third week of amdocs training , we happened to get a training for Java for single day. That day, i had heard a sentence from him which made me think of something else other than the rigid things i had stamped on my small brain. He had given a simple usual example of inheritance - Animals. Dog inherits Animal. i.e. "Dog is an animal." :)

Any technical reader now will think Its very simple and why the heck is this girl writing a big post for it??? I'd say, yes things are simple when we know them. But they are is inspiring when we come to know about them for the first time. :)

What a simple sentence! And changed my view towards inheritance. Now inheritance is not only above four things to me. Now i can think of the superclass, design it and can inherit it by a subclass. Not only when i'm told to do so. Anytime i will feel this will help me making my code flexible to change.

Now dog is an animal. My subclass is its superclass. But what's this? A child is its mother? its father? :O:O How is it possible??

Child is neither its mother nor its father. It is the entity which comes into picture when two other entities come together. This is multiple inheritance. Different from "IS-A" concept.
But why is it so different that when Inheritance is called "IS-A" relationship so widely? (This may be the reason why Java doesn't support it.)
So is multiple inheritance not a pure inheritance? If it is so, then what about the biological term? Doesn't child INHERIT from its parents? Or we can't give this analogy for OO inheritance? What is that?

This post will be updated when i will get answers to my questions.

Monday 16 February 2009

Tips for programming!!

While writing a code for a simple dotcom game on my own, I found few tips, which worked fine for my first code in java. I don't know whether they will work in future too.
They are -
1)Try to do things on your own first. Walking on unknown path with incomplete map, getting lost somewhere and finding back the way to home is fun rather than walking on a path told by someone else.

2)Don't implement the whole solution at the first step. Such code is hard to debug. Instead, write the simplest solution with least functionality and enhance it later. Make iterations.

3)Try to make it as flexible as possible. Show it to someone who will find bugs in it.
If you don't find anyone, think of the boss of Bob (or some other name) in first chapter of Head First Design Patterns.

Sunday 15 February 2009

Why This Techie Beginning?

After spending more than an hour in playing with the settings of new blog and getting nothing, I have begun to write for the beginning.

On wasting 4 years in college, then joining Amdocs, suddenly some day I realized that whatever I know about software that is equivalent to nothing. At one point I felt like giving up, but then I felt I should not be so harsh to myself. And then I gave myself one more chance to see if I can do anything more. I restarted from basics. And it is a fun!!

With guidance from real techie guys, I realized how wrong my way of learning was!! But now I can keep hopes.

As I am/was so used to my old habits of learning, in the course of acquiring new habits, many times I happen to forget the tips given to me by people or by myself. So to visualize those tips, I have started writing this blog which will remind me of those tips and will be strictly for technical things that I learn everyday. (Hope so. :D)