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.

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 ?

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.

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).

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:

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

Posts: 8

posted 6 years ago

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

Posts: 385

posted 6 years ago

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

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.

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

Posts: 385

posted 6 years ago

Could we say Generalization, Specialization and Realization , the design principles ?