Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

Commonmark migration
Source Link

From your example, it shows that you lack a basic understanding of Object-Oriented Programming. You are trying to learn how to run without having learned to stand up yet.

In your example, you assume there is a class ObjectMathFunctions. This is not Object-oriented at all, classes should model a real concept.

1. Learn about objects / classes

#1. Learn about objects / classes YouYou should first learn how classes and objects work. A class is not just any arbitrary division of code, it models something real. Examples: Car, Wheel, etc.

2. Learn about inheritance

#2. Learn about inheritance AfterAfter you understand that, learn about inheritance: a Car has a getWeight() method. A Wheel has a getWeight() method as well. Hmm, maybe they are both subdivisions of a broader concept: PhysicalThings. Every PhysicalThing has a getWeight() method.

After this, learn about overriding methods in subclasses, learn about abstract classes, etc.

3. Learn about interfaces

#3. Learn about interfaces NowNow you will understand that an interface is very similar to an abstract class. You will have done some exercises where you already encountered the problem "This is a PhysicalThing, but it is also CanExplode (e.g. wheel of car, dynamite, etc). This single inheritance model is annoying, how do I fix this?".

From your example, it shows that you lack a basic understanding of Object-Oriented Programming. You are trying to learn how to run without having learned to stand up yet.

In your example, you assume there is a class ObjectMathFunctions. This is not Object-oriented at all, classes should model a real concept.

#1. Learn about objects / classes You should first learn how classes and objects work. A class is not just any arbitrary division of code, it models something real. Examples: Car, Wheel, etc.

#2. Learn about inheritance After you understand that, learn about inheritance: a Car has a getWeight() method. A Wheel has a getWeight() method as well. Hmm, maybe they are both subdivisions of a broader concept: PhysicalThings. Every PhysicalThing has a getWeight() method.

After this, learn about overriding methods in subclasses, learn about abstract classes, etc.

#3. Learn about interfaces Now you will understand that an interface is very similar to an abstract class. You will have done some exercises where you already encountered the problem "This is a PhysicalThing, but it is also CanExplode (e.g. wheel of car, dynamite, etc). This single inheritance model is annoying, how do I fix this?".

From your example, it shows that you lack a basic understanding of Object-Oriented Programming. You are trying to learn how to run without having learned to stand up yet.

In your example, you assume there is a class ObjectMathFunctions. This is not Object-oriented at all, classes should model a real concept.

1. Learn about objects / classes

You should first learn how classes and objects work. A class is not just any arbitrary division of code, it models something real. Examples: Car, Wheel, etc.

2. Learn about inheritance

After you understand that, learn about inheritance: a Car has a getWeight() method. A Wheel has a getWeight() method as well. Hmm, maybe they are both subdivisions of a broader concept: PhysicalThings. Every PhysicalThing has a getWeight() method.

After this, learn about overriding methods in subclasses, learn about abstract classes, etc.

3. Learn about interfaces

Now you will understand that an interface is very similar to an abstract class. You will have done some exercises where you already encountered the problem "This is a PhysicalThing, but it is also CanExplode (e.g. wheel of car, dynamite, etc). This single inheritance model is annoying, how do I fix this?".

Source Link
parasietje
  • 1.5k
  • 8
  • 36

From your example, it shows that you lack a basic understanding of Object-Oriented Programming. You are trying to learn how to run without having learned to stand up yet.

In your example, you assume there is a class ObjectMathFunctions. This is not Object-oriented at all, classes should model a real concept.

#1. Learn about objects / classes You should first learn how classes and objects work. A class is not just any arbitrary division of code, it models something real. Examples: Car, Wheel, etc.

#2. Learn about inheritance After you understand that, learn about inheritance: a Car has a getWeight() method. A Wheel has a getWeight() method as well. Hmm, maybe they are both subdivisions of a broader concept: PhysicalThings. Every PhysicalThing has a getWeight() method.

After this, learn about overriding methods in subclasses, learn about abstract classes, etc.

#3. Learn about interfaces Now you will understand that an interface is very similar to an abstract class. You will have done some exercises where you already encountered the problem "This is a PhysicalThing, but it is also CanExplode (e.g. wheel of car, dynamite, etc). This single inheritance model is annoying, how do I fix this?".

lang-java

AltStyle によって変換されたページ (->オリジナル) /