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

  • SEARCH
  • Home
  • 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 468953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:44:02+00:00 2026-05-12T23:44:02+00:00

Sorry to ask sich a generic question, but I’ve been studying these and, outside

  • 0

Sorry to ask sich a generic question, but I’ve been studying these and, outside of say the head programming conveying what member MUST be in a class, I just don’t see any benefits.

  • 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-05-12T23:44:02+00:00Added an answer on May 12, 2026 at 11:44 pm

    There are two (basic) parts to object oriented programming that give newcomers trouble; the first is inheritance and the second is composition. These are the toughest to ‘get’; and once you understand those everything else is just that much easier.

    What you’re referring to is composition – e.g., what does a class do? If you go the inheritance route, it derives from an abstract class (say Dog IS A Animal) . If you use composition, then you are instituting a contract (A Car HAS A Driver/Loan/Insurance). Anyone that implements your interface must implement the methods of that interface.

    This allows for loose coupling; and doesn’t tie you down into the inheritance model where it doesn’t fit.

    Where inheritance fits, use it; but if the relationship between two classes is contractual in nature, or HAS-A vs. IS-A, then use an interface to model that part.

    Why Use Interfaces?

    For a practical example, let’s jump into a business application. If you have a repository; you’ll want to make the layer above your repository those of interfaces. That way if you have to change anything in the way the respository works, you won’t affect anything since they all obey the same contracts.

    Here’s our repository:

    public interface IUserRepository 
    {
        public void Save();
        public void Delete(int id);
        public bool Create(User user);
        public User GetUserById(int id);
    }
    

    Now, I can implement that Repository in a class:

    public class UserRepository : IRepository
    {
        public void Save()
        {
             //Implement
        }
    
        public void Delete(int id)
        {
             //Implement
        }
    
        public bool Create(User user)
        {
             //Implement
        }
        public User GetUserById(int id)
        {
             //Implement
        }
    
    }
    

    This separates the Interface from what is calling it. I could change this Class from Linq-To-SQL to inline SQL or Stored procedures, and as long as I implemented the IUserRepository interface, no one would be the wiser; and best of all, there are no classes that derive from my class that could potentially be pissed about my change.

    Inheritance and Composition: Best Friends

    Inheritance and Composition are meant to tackle different problems. Use each where it fits, and there are entire subsets of problems where you use both.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am sorry to ask this question when it has already been asked but
I'm sorry if I ask a question that's been asked before, but I could
Sorry to ask such a noob question, but the NDK documentation is wrong (r7b):
Sorry to ask this question again but I tried several solutions on stackoverflow and
I am very sorry to ask such a basic question but I am new
I'm sorry to ask a question but I am useless when it comes to
Sorry for being the 100000th person to ask the same question. But I guess
I am sorry to ask this trivial question but I could not find a
I'm sorry to ask such a simple question, but it's a specific question I've
I'm sorry to ask such a basic question, but it's kind of fundamental for

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.