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 6117597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:20:21+00:00 2026-05-23T15:20:21+00:00

Possible Duplicate: Difference between Covariance & Contra-variance I’m trying to understand what covariance and

  • 0

Possible Duplicate:
Difference between Covariance & Contra-variance

I’m trying to understand what covariance and contravariance is, as well as the difference between the two. I have looked at this link, and so far I have understood the following:

Covariance is the process by which you assign a derived member to a base member. Such as:

IEnumerable<Derived> d = new List<Derived>();
IEnumerable<Base> b = d;

I’m not even sure if I am right in the above… guess. Basically I’m looking for someone to dumb it down for me, in the simplest of terms so that I can understand what the two are and the differences between them.

I also understand there are similar topics of discussion regarding this, but most of the answers aren’t the kind of description I was looking for.

  • 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-23T15:20:21+00:00Added an answer on May 23, 2026 at 3:20 pm

    For our internal trainings I have worked with the wonderful book “Smalltalk, Objects and Design (Chamond Liu)” and I rephrased following examples. – Hope this helps…

    What does “consistency” mean?
    The idea is to design type-safe type hierarchies with highly substitutable types. The key to get this consistency is sub type based conformance.
    (We’ll discuss the Liskov Substitution Principle (LSP) on a high level here.)

    Covariance:
    Let’s assume Birds that lay Eggs “consistently” with static typing:
    If the type Bird lays an Egg, wouldn’t Bird’s subtype lay a subtype of Egg?
    E.g. the type Duck lays a DuckEgg, then the consistency is given.
    Why is this consistent? Because in such an expression:

    Egg anEgg = aBird.Lay();

    the reference aBird could be legally substituted by a Bird or by a Duck instance.
    We say the return type is covariant to the type, in which Lay() is defined.
    A subtype’s override may return a more specialized type. => “They deliver more.”

    Contravariance:
    Let’s assume Pianos that Pianists can play “consistently” with static typing:
    If a Pianist plays Piano, would she be able to play a GrandPiano?
    Wouldn’t rather a Virtuoso play a GrandPiano? (Be warned; there is a twist!) This is inconsistent! Because in such an expression:

    aPiano.Play(aPianist);

    aPiano couldn’t be legally substituted by a Piano or by a GrandPiano instance! A GrandPiano can only be played by a Virtuoso, Pianists are too general!
    GrandPianos must be playable by more general types, then the play is consistent.
    We say the parameter type is contravariant to the type, in which Play() is defined.
    A subtype’s override may accept a more generalized type. => “They require less.”

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

Sidebar

Related Questions

Possible Duplicate: What is the difference between using a struct with two fields and
Possible Duplicate: Difference between a Structure and a Union in C I could understand
Possible Duplicate: What is the difference between "typename" and "class" template parameters? When defining
Possible Duplicate: What's the difference between NOT EXISTS vs. NOT IN vs. LEFT JOIN
Possible duplicate Debug Visual Studio Release in .NET What is the difference between Debug
Possible Duplicate: Difference between pointer variable and reference variable in C++ When should I
Possible Duplicate: Difference between -%> and %> in rails So for an ERB file,
Possible Duplicate: Difference between -%> and %> in rails I need to know what
Possible Duplicate: Difference between a Structure and a Union in C I see this
Possible Duplicate: Difference between lock(locker) and lock(variable_which_I_am_using) In all of the thread-safe code examples

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.