2 replaced http://programmers.stackexchange.com/ with https://softwareengineering.stackexchange.com/
source | link

Inheritance is used all the time when writing object-oriented code. In most OO languages, (with C++ being a prominent exception,) all objects have a single "base object" class that they derive from that provides common functionality, so literally everything that uses an object uses inheritance.

Beyond that obvious point, there are many times when you'll find that you need several different types of object that share a lot of important traits in common. Inheritance is very useful here. For example, if you've ever built a GUI in an object-oriented language, you probably used a framework where all of the graphical controls had a common parent class that handled a bunch of functionality that all the controls in the windowing system they run on need to cover. And if you do any work with parsing or code generation, (which are basically two sides of the same coin) you'll quickly run into other examples where a base class with a bunch of derived classes are useful.

It's true that inheritance is not the only way to make objects work together; you can also use composition, (where one object contains another object of a different type,) which works better in some cases. Be careful about treating this as a point of dogmaBe careful about treating this as a point of dogma, though. Inheritance is a very useful tool if you know what you're doing. So is composition, and neither one of them is really a good substitute for the other. The important thing is to know what you're doing, and if you don't, learn and experiment and develop your knowledge and your skills. (And feel free to ask questions on here or StackOverflow!)

Inheritance is used all the time when writing object-oriented code. In most OO languages, (with C++ being a prominent exception,) all objects have a single "base object" class that they derive from that provides common functionality, so literally everything that uses an object uses inheritance.

Beyond that obvious point, there are many times when you'll find that you need several different types of object that share a lot of important traits in common. Inheritance is very useful here. For example, if you've ever built a GUI in an object-oriented language, you probably used a framework where all of the graphical controls had a common parent class that handled a bunch of functionality that all the controls in the windowing system they run on need to cover. And if you do any work with parsing or code generation, (which are basically two sides of the same coin) you'll quickly run into other examples where a base class with a bunch of derived classes are useful.

It's true that inheritance is not the only way to make objects work together; you can also use composition, (where one object contains another object of a different type,) which works better in some cases. Be careful about treating this as a point of dogma, though. Inheritance is a very useful tool if you know what you're doing. So is composition, and neither one of them is really a good substitute for the other. The important thing is to know what you're doing, and if you don't, learn and experiment and develop your knowledge and your skills. (And feel free to ask questions on here or StackOverflow!)

Inheritance is used all the time when writing object-oriented code. In most OO languages, (with C++ being a prominent exception,) all objects have a single "base object" class that they derive from that provides common functionality, so literally everything that uses an object uses inheritance.

Beyond that obvious point, there are many times when you'll find that you need several different types of object that share a lot of important traits in common. Inheritance is very useful here. For example, if you've ever built a GUI in an object-oriented language, you probably used a framework where all of the graphical controls had a common parent class that handled a bunch of functionality that all the controls in the windowing system they run on need to cover. And if you do any work with parsing or code generation, (which are basically two sides of the same coin) you'll quickly run into other examples where a base class with a bunch of derived classes are useful.

It's true that inheritance is not the only way to make objects work together; you can also use composition, (where one object contains another object of a different type,) which works better in some cases. Be careful about treating this as a point of dogma, though. Inheritance is a very useful tool if you know what you're doing. So is composition, and neither one of them is really a good substitute for the other. The important thing is to know what you're doing, and if you don't, learn and experiment and develop your knowledge and your skills. (And feel free to ask questions on here or StackOverflow!)

1
source | link

Inheritance is used all the time when writing object-oriented code. In most OO languages, (with C++ being a prominent exception,) all objects have a single "base object" class that they derive from that provides common functionality, so literally everything that uses an object uses inheritance.

Beyond that obvious point, there are many times when you'll find that you need several different types of object that share a lot of important traits in common. Inheritance is very useful here. For example, if you've ever built a GUI in an object-oriented language, you probably used a framework where all of the graphical controls had a common parent class that handled a bunch of functionality that all the controls in the windowing system they run on need to cover. And if you do any work with parsing or code generation, (which are basically two sides of the same coin) you'll quickly run into other examples where a base class with a bunch of derived classes are useful.

It's true that inheritance is not the only way to make objects work together; you can also use composition, (where one object contains another object of a different type,) which works better in some cases. Be careful about treating this as a point of dogma, though. Inheritance is a very useful tool if you know what you're doing. So is composition, and neither one of them is really a good substitute for the other. The important thing is to know what you're doing, and if you don't, learn and experiment and develop your knowledge and your skills. (And feel free to ask questions on here or StackOverflow!)