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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:01:27+00:00 2026-06-07T23:01:27+00:00

As the title says, I share the same logic between an UIViewController and an

  • 0

As the title says, I share the same logic between an UIViewController and an UITableViewCell, which send some info to a server and do some calculus.

I’m having the problem that the replicated code is bigger as time passes but I don’t know how to factorize this because the clases are different objects and each function call instance variables.

Which is a good way to re-factorize the code so I don’t have to change the same code twice everytime?

  • 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-07T23:01:28+00:00Added an answer on June 7, 2026 at 11:01 pm

    The simplest way of refactoring a duplicated code is to make a method out of the common part. An important question is where to put it. When the objects are related, you can put the common code in their common ancestor; when they are not related, you might consider creating a helper class with only class methods, or defining a C-style freestanding function with the body of your method.

    In case the objects are unrelated and you need to use their instance variables, there may be an opportunity to extract a common object. Move all common instance variables needed for the duplicated code into the new common object, along with the code that uses these variables. If the variables are also needed in the original classes from which you have extracted the common part, add getters and setters as needed. Create an ivar for the extracted class, and use its properties in place of the instance variables.

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

Sidebar

Related Questions

Pretty much as the title says, does a non-fixed table-layout share the same performance
As title says, i know that new throws an exception which can be caught,
As title says for some purpose I need to get the size of request/response
As title says, im having trouble with my junit tests passing for checking if
Title says it all: What is the difference between a UserTransaction and an EntityTransaction
As title says, is there a way to send form when element outside of
The title says What is the difference between release and iteration? Can you explain
Well as the title says i have 2 web projects that have the same
The title says it. I'm looking for a way to determine exactly which file/registry
The title says it - What happens between TestMethods in MS Visual Studio Unit

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.