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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:17:47+00:00 2026-06-03T05:17:47+00:00

i am using codeigniter. i have class Orders which with some methods like start_order(),

  • 0

i am using codeigniter.

i have class Orders which with some methods like start_order(), close_order(), etc..

and i have a permission level for each user type 'admin','salesman','manager' ..

therefore the same method may get different implementation each time.

so, my question is: which is considered as best practice in CI :

1) to make a big method in the ‘orders’ class that contains the
different logic details. or
2) repeat the method as needed in
other classes.

i know it sounds obvious that one should go for the first choice. but, when i did that i ended up with massive blocks of code. so, this is why i am asking for your experience.

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

    As a matter of fact it is not obvious that one should go for the first choice (“one big method”). That should definitely be avoided.

    In general, one should prefer small methods. Each method should do exactly one thing and only one thing, have only one reason to ever change, be small and readable, be obvious from its name what it is doing, etc.

    The wording you choose in your question (“different implementation each time” and “that contains the different logic details”) implies that you’re talking about one method which does different things based on some kind of state of the objects.

    Take a look at a refactoring pattern called Replace Conditional With Polymorphism. This pattern is commonly used when you have a method which is primarily a big case check or an if/elseif chain which determines that state. The idea is that you’d extract each implementation into its own class which overrides a method on a base class. The classes would hold and know about the state and would be able to apply the correct logic accordingly, and the consuming code would just call the method on the base class type.

    There is lots of information and lots of examples on this pattern.

    As @Gordon points out, this is also called the Strategy Pattern.

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

Sidebar

Related Questions

I'm using CodeIgniter (because it's awesome) and I have something like: <?php echo anchor(/,
I'm using Codeigniter/PyroCMS which uses ion_auth. I have my session stuff set for two
Using CodeIgniter's Active Record class and MySQL, I have a table of posts with
I have a controller something like this in codeigniter: class ABC extends MX_Controller {
I am using Codeigniter to build my project. Here i have some doubts or
I have a callback function for CURLOPT_PROGRESSFUNCTION in codeigniter like below: class download_model extends
i'm using Codeigniter. i have a form which takes information about users. What i
I have an application built with codeigniter using the sessions class and storing session
I am using CodeIgniter and I have two different controllers - login.php and site.php
Currently I have create a website using codeigniter. I got a message error every

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.