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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:03:44+00:00 2026-06-02T05:03:44+00:00

My class represents states of various systems. Each instance has two attributes: one is

  • 0

My class represents states of various systems. Each instance has two attributes: one is a container shared between all the states of the same system, and the other is a container that is unique to each instance.

A copy of a state should reuse the “shared” attribute, but create a deep copy of the “unique” attribute. This is really the only copy semantics that makes sense (it’s natural that the copy of a state is a state of the same system).

I want to create the least surprise for people who read and maintain my code. Should I override __deepcopy__ or __copy__ for my purposes?

  • 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-02T05:03:48+00:00Added an answer on June 2, 2026 at 5:03 am

    Is it really necessary to use the copy module for copying instances of this class? I would argue that instead of overriding __copy__ or __deepcopy__ you should create a copy method for your class that returns a new object using the copy semantics you defined.

    If for some consistency reason you do need to use the copy module, then in my opinion __deepcopy__ is more appropriate. If it is a defined behavior of the class that all instances share one of the containers, then it is reasonable to assume that an implementation of __deepcopy__ would respect that.

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

Sidebar

Related Questions

I have class that represents users. Users are divided into two groups with different
I have two ActiveRecord models of the same class: #1: represents the current committed
I have a class that represents the state of the world. The class has
Say I have a class which represents a person, a variable within that class
I have a Location class which represents a location somewhere in a stream. (The
Suppose I’m making an Objective-C class that represents a fraction, and want to create
Here is my custom class that I have that represents a triangle. I'm trying
Is there a class in the ASP.NET MVC framework that represents a controller name
I have a class, called Media, which represents coredata. If something changes in my
[Objective-C] Do you still use Styrofoam balls to model your systems, where each ball

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.