Showing posts with label article. Show all posts
Showing posts with label article. Show all posts

Saturday, May 12, 2018

What is Inheritance in Java? Here is Detail Explanation of Inheritance

What  Inheritance is? Perhaps for those who learning about object oriented programming (OOP) have heard about this concept. Maybe there are some people have understood about Inheritance or there are still confuse about how Inheritance really work.

This article will guide you who learning object oriented programming and still don't understand the concept of Inheritance.

What Inheritance is?


Inheritance is the process of inheriting data/method from super class to its sub class. What does it means? It means what is owned by super class (read : method/process) is also owned by its sub class.



What is the characteristic of class that use Inheritance concept?


The main characteristic that you can find is that class will use extends to its super class. For example :


From the snippet above, Class Tree as Super Class and Class Pine as Sub Class. Whatever data/method/process that owned by Class Tree is also owned by Class Pine.

Is all extends means that class has implement Inheritance concept?


Basically yes, but we have to get the concept of Inheritance, why developers created Inheritance model? Have you thinking about it?

Inheritance concept created in order to make easy developers to access the same method/function in various classes by extends the super class.

But there are some things that must be thought out before you implement Inheritance in your project, here are they :
  1. Make sure you have understood the flow of your program and its characteristic (is that related with the Car, People or the thing that have much entities inside it)
  2. If you create a class that contains function/method, thought first, is that method will used much time in different classes or not
  3. How often we will call the same method or function
  4. How important the method or function in class where will use it.
If you requirements like the 4 point above, you should use the Inheritance concept. But if now, there is no problem with that, here we talk about the best practice implementation of Inheritance.

Example :

If you create super class called Class Tree, the create sub class called Class Yamaha, and then the Class Yamaha extends Tree{}. it totally wrong! We should extends that much related with the Super Class, not just do extends like what you will. haha

Until here, understood?

So, what is the right characteristic that can implement Inheritance concept?


There are much example that can implement the Inheritance concept, here I will give you one :

Characteristic of Hospital

Super Class :
  • Class name : Hospital{...}
  • Method : hospitalName(...), hospitalAddress(....)
Sub Class :
  • Class name : Employee{...}
  • Method : employeeName(...), employeeAge(....)

Perhaps one of you have a question and asking "What the relation of Class Employee and Class Hospital?"

Well, the sure thing is the hospital must have employees, right? either it doctor, back office, front office or other staff. Those employees must be have an identity (looks like idcard) where are they work, so Class Employee has to extends Class Hospital as its Super Class.

Project Example


In order make you clear understand the concept of Inheritance, let implement the characteristic of the Hospital above

Class Hospital

Class Employee

Main Program

Take a loot at the codes above, method setHospitalName and setHospitalAddress called directly from its Super Class. Why? Because those methods will call repeated, so that methods wrote in its Super Class (Class Hospital).

The output of the program above is :


Okay that is the explanation about how Inheritance works, hope you'll understand. Thank you.

Friday, April 27, 2018

Newbie, Here are some references how to asking programming questions

This article will talking about how to be great at asking programming questions, especially for those who new programming world.

Why I said for those who new in programming language?


Yeah, mostly of them asking their programming problem with bad (sometime worst) questions and no explain clearly about their problem.


For example (bad questions) :
  • I need to create simple chat program, could you provide me the source code? (hahaha hell yeah)
  • Sir I got error in every sign in with Facebook from my application, how to fix it? (with no code attached, seriously? haha)
  • Here my code, when I using this code, the application always crash, I don't know how to fix it. Please help me! (We don't know exactly what the problem, have you debugged it?)
  • How to learn ABC programming?
  • How to learn ABC programming instantly? (hahaha)
  • etc
If you are join in some programming groups / forums, you must be face the question similar like that, right? haha,

How to be great at asking programming questions?


There are some type of good programming questions, as long as the questions is clearly describe about your problem, it will be fine.

For reference, here are some good way how to asking programming questions (copied from stackoverflow) :
  • Bad : C# Math Confution
  • Good : Why does using float instead of int give me different results when all of my inputs are integers?
  • Bad :  [php] session doubt
  • Good : How can I redirect users to different pages based on session data in PHP? (You have to attached to code, if not, your question will be in to bad category questions)
  • Bad : android if else problem (your question not clearly enough)
  • Good : Why does str = "value" evaluate to false when str is set to "value"?
To avoid bad reputation because of your question, try to do some steps that make your questions a little bit clearly.


Explain The Problem


Sometimes people who asking their question with no detail explanation, like : How to create Facebook login in our application?, insane!

You should tried coding first by your selves, then find the error and explain the difficulty, by providing the clear question it will be much people excited to answer your questions. Don't forget to provide the code!

Provide the code snippet


This is the most important thing. You have to provide the codes and explain your problem related to your code snippet.

If you are follow some tutorials, just attached the link where you find the tutorial after that tell people which line of those tutorial that give you an error. But, in some case people need you attached full code of your class.


If people mark you as duplicate questions, what should you do?


Talking about programming, we also talking about abstract problem. Perhaps your questions look similar like others that has been solved and your question marked as "possible duplicated". If it happened to you, don't worry, if you think your questions is different, then tell other what the different of your question by edit your question and provide some descriptions.

Also, you have to tell people that you have tried all answers that similar with your questions. don't forget to provide the link's answers.

But, if your question indeed similar like others, and you never try the others answer, you question will be down voted or maybe closed.

Be interactive with people who answer your question.


This makes you easier to find the most appropriate answer to your question. For example if there any answers and it not what you looking for, you should comment the answer and tell what you really needed.

If you have no idea of the result from the answer that given to you, you have to try it first into your program, whatever the result you still have to tell the owner of the answer, like "I have tried your answer, but it still doesn't work." or "Nice, your code works, thank you".

Actually there are much reference how to be great at asking programming language, this article just a little bit my experience when asking programming questions. Hope this article will guide you how to be great at asking programming questions.