GeeCON Prague 2014*
The moose likes Java in General and the fly likes Realization and Generalization in Java / Object Oriented Programming Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Realization and Generalization in Java / Object Oriented Programming" Watch "Realization and Generalization in Java / Object Oriented Programming" New topic
Author

Realization and Generalization in Java / Object Oriented Programming

Azrael Noor
Ranch Hand

Joined: Jul 29, 2010
Posts: 382
I have found these two definitions of online:

Realization : means Implementing an Interface.
Generalization : means Extending a Class

which means Realization is not Extending an Abstract class, and extending an abstract class is Generalization

and it is written that these concepts are basically used in UML, as i have not studied this Language
still i wanted to know that:
does it really not used in JAVA

We are using these two daily or may be i am unable to understand term properly

Please explain terms in context with Java, thank you


Regards
Azrael Noor
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14194
    
  20

Those two words are not really common words that Java developers use, as far as I know. At least, I've never heard people calling implementing an interface "realization", and extending a class is really the opposite of generalization; a subclass is a specialized version of its superclass, not a generalized one.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Azrael Noor
Ranch Hand

Joined: Jul 29, 2010
Posts: 382
Jesper de Jong wrote:Those two words are not really common words that Java developers use, as far as I know. At least, I've never heard people calling implementing an interface "realization", and extending a class is really the opposite of generalization; a subclass is a specialized version of its superclass, not a generalized one.


Specialized means specific to Super class right?

Yupz, i found that Specialization means creating new subclasses from an existing class.

but i also read

Generalization is the process of extracting shared characteristics from two or more classes,
and combining them into a generalized superclass <------- Don't we use this in JAVA ?


Gaurangkumar Khalasi
Ranch Hand

Joined: Jun 02, 2012
Posts: 187
Azrael Noor wrote:
but i also read

Generalization is the process of extracting shared characteristics from two or more classes,
and combining them into a generalized superclass <------- Don't we use this in JAVA ?


Let's understand with examples.

My name is Gaurangkumar Khalasi (Firstname Lastname).

So, for my fullname:

"Khalasi" is a Generalization for me and others having this surname.
and
"Gaurangkumar Khalasi" is specialization i.e. specialized version of "Khalasi".

In the same way, for Java both concepts are used.
For example,
Car IS-A Vehicle --> Specialization --> class Car extends Vehicle
But if you think above case in reverse, i.e. "Vehicle" is a Generalization for Car,Scooter,Bicycle,etc... than it is a Generalization.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39079
    
  23
I would agree with Jesper and say not to use realisation or generalisation at all.
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4474
    
    6

Azrael Noor wrote:Generalization is the process of extracting shared characteristics from two or more classes,
and combining them into a generalized superclass <------- Don't we use this in JAVA ?

This is not specific to Java and it's not so much a feature of the language as it is a design adjustment (refactoring). It's something that a developer/designer does when he realizes that there is some kind of common behavior between two or more classes that can be consolidated to eliminate duplication. If you use an IDE that has refactoring utilities like Eclipse, this is pretty easy to do: in the editor, you would highlight the method you want to move to a superclass, right click, then select Refactor -> Pull Up. See http://www.ibm.com/developerworks/library/os-ecref/ for more on refactoring in Eclipse (kind of old article but it gives you a good idea of the motivations for doing these things).


Junilu - [How to Ask Questions] [How to Answer Questions]
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14194
    
  20

To make the point about specialization more clear:

Suppose you have a class named Animal. Now you can create subclasses of Animal - for example Dog extends Animal, Cat extends Animal. Dogs and cats are specific types of animals. So, if you create a subclass of Animal, you're creating a class that represents a specialized kind of Animal.

The other way around: Suppose that you didn't have the class Animal at first, but you did have different classes for different animals, such as Dog and Cat. Now you decide to take the parts that are common to dogs and cats and you put them in a common superclass Animal (you make Dog and Cat extend Animal). You could call that generalization. But that's the opposite of what you said in your post:
Azrael Noor wrote:Generalization : means Extending a Class

praveen murali
Greenhorn

Joined: Jun 02, 2012
Posts: 8
Azrael Noor wrote:
Jesper de Jong wrote:
Generalization is the process of extracting shared characteristics from two or more classes,
and combining them into a generalized superclass <------- Don't we use this in JAVA ?




A superclass is a generalized form of one or more sub-classes. The examples above are good enough to explain the theory.
praveen murali
Greenhorn

Joined: Jun 02, 2012
Posts: 8
Junilu Lacar wrote: If you use an IDE that has refactoring utilities like Eclipse, this is pretty easy to do: in the editor, you would highlight the method you want to move to a superclass, right click, then select Refactor -> Pull Up.


That was helpful, thanks, didn't know that.
Azrael Noor
Ranch Hand

Joined: Jul 29, 2010
Posts: 382
Thank you all.
Facts are quite cleared
about Generalization and Specialization

but Realization part is not understood till yet.
Mr. Jong said that It is not used in Java but it is still parts of OOPS

If anyone continue with this part, i shall be thankful .
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

Realization is basically a UML term used to denote a semantic relationship between two entities where one of them specifies a contract that another one guarantees to fulfill.
Since UML is Java-independent (actually any-technology-independent) it is basically just the difference in terminology. What is called realization in UML, you can refer to as interface implementation in Java.


The quieter you are, the more you are able to hear.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4397
    
    8

Jesper de Jong wrote:The other way around: Suppose that you didn't have the class Animal at first, but you did have different classes for different animals, such as Dog and Cat. Now you decide to take the parts that are common to dogs and cats and you put them in a common superclass Animal (you make Dog and Cat extend Animal). You could call that generalization.


I'd say that is the common meaning of generalization - it's fairly standard usage when talking about object-oriented concepts, though possibly not so much when specifically applied to Java. For instance, it's the term that the UML specification uses. I teach on a course on object-oriented software development, and it uses the terms generalization/specialization as opposites in exactly this way.
Azrael Noor
Ranch Hand

Joined: Jul 29, 2010
Posts: 382
Could we say Generalization, Specialization and Realization , the design principles ?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39079
    
  23
No
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Realization and Generalization in Java / Object Oriented Programming