0

JavaBean inheritance seems redundant since it does pretty much the same exact thing as a java class inheritance.

In fact, much of JavaBean conventions/rules are redundant to OO and JAVA.

Thus: what is the difference between the two inheritances?

GhostCat
  • 137,827
  • 25
  • 176
  • 248
coderg
  • 85
  • 2
  • 8
  • 1
    What is java bean inheritance? Mind giving an example? – GhostCat Apr 19 '17 at 03:14
  • 1
    A JavaBean is a POJO (plain old Java Object), that follows some additional rules to support common tools. – Elliott Frisch Apr 19 '17 at 03:17
  • @elliot frisch yes correct, but those conventions are nothing different from standard OO rules and JAVA features...ITS REDUNDANT. – coderg Apr 19 '17 at 03:19
  • 1
    Inheritance in both are the same, JavaBean is also a java class. – Bahramdun Adil Apr 19 '17 at 03:20
  • @bahramdun to my point that javabean conventions/rules are redundant and need exist because they already exist in JAVA and OO lol.... – coderg Apr 19 '17 at 03:22
  • 1
    You seem to be misunderstanding JavaBeans, as many people have already answered on your previous question [Why aren't javabean features built into the root JAVA object?](https://stackoverflow.com/questions/43484854/why-arent-javabean-features-built-into-the-root-java-object) Stop and read a good JavaBeans tutorial before posting further vague questions based on the incorrect notation that there is somehow a big difference between a JavaBean and other Java objects. There isn't. – Erwin Bolwidt Apr 19 '17 at 03:22
  • @ErwinBolwidt so then whats the point of having separate rules to follow for a javabean when its already there in the language? – coderg Apr 19 '17 at 03:25
  • 1
    There **are no separate rules** for JavaBeans inheritance. See [What is a JavaBean exactly?](http://stackoverflow.com/questions/3295496/what-is-a-javabean-exactly) and the [JavaBeans specification](http://download.oracle.com/otn-pub/jcp/7224-javabeans-1.01-fr-spec-oth-JSpec/beans.101.pdf) – Erwin Bolwidt Apr 19 '17 at 03:30
  • Thanks for the accept. – GhostCat Apr 25 '17 at 02:22

1 Answers1

2

Given your comments, I think I understand your problem by now: you expect "all things" to be consistent and well defined in Java.

That idea is unfortunately not true. Keep in mind that java has 20+ years of history. Beans were part of the language from early on (there were ideas of having Bean-based tools for nice, generic plugging of applications). A lot of that was dreamed up, but never gained much success.

So certain concepts were never followed up upon later on. On the other hand, java is about backwards compatibility, so things that are in, stay in - even when they don't make much sense any more.

And I agree with the comment by Erwin: you are overthinking... in this sense: "bean" is not a fixed element of the Java language; for example beans are not described in the Java Language Specification document. Beans are just an informal concept.

In other words: a Java class is first of all a Java class. If it follows the bean conventions, we call it a bean. Thus there is actually no such thing as "bean" inheritance. Long story short: I think you are overthinking this.

Community
  • 1
  • 1
GhostCat
  • 137,827
  • 25
  • 176
  • 248
  • Thank you very much. That sums it up. It's basically a convention to follow for a class that encapsulated other objects with certain rules to adhere to. I was getting really confused because I'm using the framework Spring MVC and it uses XML files to manipulate the bean(class) and re-introduces many OO concepts(like inheritance) for the xml bean files. Redundant isn't it? – coderg Apr 19 '17 at 08:09
  • Sure. But following a basic rule in computer science: you can solve every problem by adding another layer of abstraction! Even when you already got a similar layer. Annoyingly redundant that is. – GhostCat Apr 19 '17 at 08:12
  • See this is why JAVA is great, and my other languages/frameworks/apis/conventions are not lol...because JAVA is proven and not redundant much like relational databases. And also when should make your classes follow bean convention? Also why not have a interface that has the skeleton that follows bean convention and any class that is to be a bean, implements that interface? – coderg Apr 19 '17 at 08:14
  • Lets not get too much into discussions; but: programming languages (and their concepts) are tools. As a professional, you simply have a variety of tools you know about. You pick the one that best fits your requirements when implementing a solution. So, when you are using spring, and daos, and stuff; then beans aren't far away. But when you do functional programming, then you strive for "immutable" classes and create totally non-bean classes. There isn't one solution that fits all problems. – GhostCat Apr 19 '17 at 08:17