Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7876383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:09:31+00:00 2026-06-03T03:09:31+00:00

When creating classes, is there a rule for when to use inheritance and when

  • 0

When creating classes, is there a rule for when to use inheritance and when to import a new class, without inheritance, into another?

Here’s an example:

I make a class called Person, and then create lots of Person objects.

I then create a child class called House. Using inheritance and properties, all my Person objects can now have a House.

I then create a child class called Car so all my Person objects now have Houses and Cars.

and so on… and so on….

I now have this sequence of classes:

NSObject < Person < House < Car < new Class < another new Class, etc.

With the above scenario, my logic (I’m an Objective-C beginner) tells me I have two different ways of producing the same outcome:

  1. As explained above, or
  2. Create each class without inheritance and then import it into Person as an ivar – for example, an instance of House now becomes a type, and that is then imported into a Person object using properties.

Please excuse my lack of terminology and understanding. If required, I can upload a code example but it’s more of a general question on when and when not to use inheritance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T03:09:31+00:00Added an answer on June 3, 2026 at 3:09 am

    This question is not specific to Objective-C: the guideline for when to use inheritance is the same for all object-oriented languages, and it is based on substitutability, summarized by the Liskov Substitution Principle:

    if S is a subtype of T, then objects of type T may be replaced with objects of type S

    In other words, use inheritance only when you can say “{derived} is a {base}>”; when you model a “{owner} has a {something}”, use composition

    • Student is a Person — Inheritance
    • Car is a vehicle — Inheritance
    • Person has a House — Composition (ivar or property)
    • Car has a(n) Engine — Composition (ivar or property)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I frequently find myself creating classes which use this form (A): abstract class Animal
Essentially, I am just creating two classes where one class, in this case class
i've been creating functions for too long without taking my code to 'classes'. I
I know that there are people out there creating classes for this (ie http://coreyoneil.com/portfolio/index.php?project=5
While creating classes, I followed OO conventions and declared all class variables before using
Sometimes it`s not convenient to use standart activity methods for creating ContextMenu (because there
I have a source code that is needed to be converted by creating classes,
I'm just getting my head round C#. I've been creating classes and objects so
I'm creating interfaces and abstract classes that represent a messaging framework for short text-based
I'm having trouble creating a global function accessible from within all classes. I receive

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.