Skip to main content
deleted 8 characters in body
Source Link
Ben Cottrell
  • 12.1k
  • 4
  • 33
  • 44

the OO Principles you mention in the first list are guidelines for program design. (there are others aside from those too; SOLID for example.)

OO Principles are a collection of ideas and part of the OO mindset; understanding OO principles such as Abstraction, Encapsulation and Modularity will help you make good design decisions when faced with the task of creating new classes in code.

Some of those decisions might include

  • What name do I choose for a class or Method?
  • Which class does a Method or Field/Property belong to?
  • Should I add this line of code to a Method or create a new one?
  • Should a class be split into multiple separate classes?
  • Should two classes be merged together?
  • Which other classes should have access to a class' interface?

On the other hand, Polymorphism and Inheritance are not principles but language tools; just as for and while are language tools.

While they are often cited as being defining among the defining language features of OO Programming, that line of thinking is actually a bitsomewhat misguided because they'rethey can be used in ways which grind against a lot of OO principles. A lot of exceptionally good OO code has been written without using inheritance or polymorphism.

There are occasions when inheritance and polymorphism are useful tools, just as there are occasions when do..while or switch are useful tools; and you should certainly understand what they are and how/when to use them.

However it's a mistake to consider either Inheritance or Polymorphism as OO principles, or that they are 'goals' to work towards. The reality is that they can and frequently are abused, resulting in bad code (usually by programmers who assume that any use of inheritance is a good thing, or who treat inheritance as their go-to tool for code reuse).

the OO Principles you mention in the first list are guidelines for program design. (there are others aside from those too; SOLID for example.)

OO Principles are a collection of ideas and part of the OO mindset; understanding OO principles such as Abstraction, Encapsulation and Modularity will help you make good design decisions when faced with the task of creating new classes in code.

Some of those decisions might include

  • What name do I choose for a class or Method?
  • Which class does a Method or Field/Property belong to?
  • Should I add this line of code to a Method or create a new one?
  • Should a class be split into multiple separate classes?
  • Should two classes be merged together?
  • Which other classes should have access to a class' interface?

On the other hand, Polymorphism and Inheritance are not principles but language tools; just as for and while are language tools.

While they are often cited as being defining among the language features of OO Programming, that line of thinking is actually a bit misguided because they're used in ways which grind against a lot of OO principles. A lot of exceptionally good OO code has been written without using inheritance or polymorphism.

There are occasions when inheritance and polymorphism are useful tools, just as there are occasions when do..while or switch are useful tools; and you should certainly understand what they are and how/when to use them.

However it's a mistake to consider either Inheritance or Polymorphism as OO principles, or that they are 'goals' to work towards. The reality is that they can and frequently are abused, resulting in bad code (usually by programmers who assume that any use of inheritance is a good thing, or who treat inheritance as their go-to tool for code reuse).

the OO Principles you mention in the first list are guidelines for program design. (there are others aside from those too; SOLID for example.)

OO Principles are a collection of ideas and part of the OO mindset; understanding OO principles such as Abstraction, Encapsulation and Modularity will help you make good design decisions when faced with the task of creating new classes in code.

Some of those decisions might include

  • What name do I choose for a class or Method?
  • Which class does a Method or Field/Property belong to?
  • Should I add this line of code to a Method or create a new one?
  • Should a class be split into multiple separate classes?
  • Should two classes be merged together?
  • Which other classes should have access to a class' interface?

On the other hand, Polymorphism and Inheritance are not principles but language tools; just as for and while are language tools.

While they are often cited as being the defining language features of OO Programming, that line of thinking is somewhat misguided because they can be used in ways which grind against a lot of OO principles. A lot of exceptionally good OO code has been written without using inheritance or polymorphism.

There are occasions when inheritance and polymorphism are useful tools, just as there are occasions when do..while or switch are useful tools; and you should certainly understand what they are and how/when to use them.

However it's a mistake to consider either Inheritance or Polymorphism as OO principles, or that they are 'goals' to work towards. The reality is that they can and frequently are abused, resulting in bad code (usually by programmers who assume that any use of inheritance is a good thing, or who treat inheritance as their go-to tool for code reuse).

Source Link
Ben Cottrell
  • 12.1k
  • 4
  • 33
  • 44

the OO Principles you mention in the first list are guidelines for program design. (there are others aside from those too; SOLID for example.)

OO Principles are a collection of ideas and part of the OO mindset; understanding OO principles such as Abstraction, Encapsulation and Modularity will help you make good design decisions when faced with the task of creating new classes in code.

Some of those decisions might include

  • What name do I choose for a class or Method?
  • Which class does a Method or Field/Property belong to?
  • Should I add this line of code to a Method or create a new one?
  • Should a class be split into multiple separate classes?
  • Should two classes be merged together?
  • Which other classes should have access to a class' interface?

On the other hand, Polymorphism and Inheritance are not principles but language tools; just as for and while are language tools.

While they are often cited as being defining among the language features of OO Programming, that line of thinking is actually a bit misguided because they're used in ways which grind against a lot of OO principles. A lot of exceptionally good OO code has been written without using inheritance or polymorphism.

There are occasions when inheritance and polymorphism are useful tools, just as there are occasions when do..while or switch are useful tools; and you should certainly understand what they are and how/when to use them.

However it's a mistake to consider either Inheritance or Polymorphism as OO principles, or that they are 'goals' to work towards. The reality is that they can and frequently are abused, resulting in bad code (usually by programmers who assume that any use of inheritance is a good thing, or who treat inheritance as their go-to tool for code reuse).