• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

should you always program with inheritance in mind?  RSS feed

 
Ranch Hand
Posts: 377
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,

i know silly little programs dont require you to use inheritance...you can just program using a few classes etc
but where do you draw the line?
when does it become necessary to start using inheritance?
am i right in saying that inheritance down the line will make it easier to scale a project...adding things and changing things will be easier if using inheritance?
is it something i should start implementing from the get go?
any info appreciated

  
 
Saloon Keeper
Posts: 4734
52
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Inheritance is a tool, it has its places where it's the right tool for the job.

In very basic terms, when you read through your requirements look for:

  • NOUNS These will become classes
  • VERBS These will become methods
  • IS-A relationships will become inheritance
  • HAS-A relationships will become aggregations

  • A car IS-A vehical, for instance - inheritance.
    A car HAS-A engine - aggregation.

    Among other things, inheritance reduces code duplication.
    Inheritance is a way of implementing polymorphism.
     
    Marshal
    Posts: 60060
    188
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Yes, you shou‍ld be practising inheritance from early stages in your career. Unfortunately, you need to know about things like the Liskov Substitution Principle. More details here. Note the classic counter‑example of the square and rectangle.
    You will unfortunately learn with experience that in many circumstances, inheritance causes more harm than good.
     
    Campbell Ritchie
    Marshal
    Posts: 60060
    188
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Somebody said they were having difficulties opening the first link in my previous post. Maybe this pdf will be easier to open.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!