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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:20:39+00:00 2026-05-22T01:20:39+00:00

A lot has been said about mutable / immutable objects in the data model.

  • 0

A lot has been said about mutable / immutable objects in the data model.

But what about the business logic? For example: a CD player. One class is responsible for playing the CD.

// Immutable version:
class Player
{
    CD cd;
    public Player(CD cd) { ... }
}

// Mutable version:
class Player
{
    CD cd;
    public void ChangeCD(CD cd) { ... }
}

I can think of several subtle advantages and disadvantages to both versions.
For example, when player is mutable, other objects can take the player and it stays valid even if the CD changes. When player is immutable, you need a wrapper object (e.g. Command Pattern) that gets updated when a new Player is created.

Which version is preferable in which cases? Are there any general guidelines?

  • 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-22T01:20:39+00:00Added an answer on May 22, 2026 at 1:20 am

    Here’s a third option.

    class Player
    {
         // private CD myCD <- no private field for the CD
         public Player() {}
         public void playCD (CD cd) {}
    }
    

    A player should never own a CD object. It should just be told here is a CD object, play it.

    A better option would be

    class CDPlayer : DataPlayer
    {
        public Player() {}
        public void playData (IData cd) {}
    }
    
    class CD : IData {}
    

    If you reduce the amount of coupling between your CD and Player then you really don’t have to think too hard about this.

    I believe your example is a bit flawed with respect to your actual question.

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

Sidebar

Related Questions

I know this has been discussed a lot of times but is there any
Lot of questions has been already asked about the differences between string and string
There has been a lot of talk about contra-revolutionary NoSQL databases like Cassandra ,
I know a lot has been written about Linq and it's inner workings. Inspired
There has been a lot of sentiment to include a nameof operator in C#.
There has been a lot of talk around iPad-Apps / Approval / Store-related Questions.
This problem has been solved! Thanks a lot to Brad, Denis and junkie! You're
I've been give some lovely Java code that has a lot of things like
.NET has a lot of complex data structures. Unfortunately, some of them are quite
Our solution has a lot of todo comments, but unfortunately it seems the only

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.