Suppose a have a controller (let’s call it “main”) and an associated model which performs a bunch (10) of functions.
i’m wondering about the associated overhead in loading a 2nd model to do one function that doesn’t exist in the main model vs. just adding that function (duplicating the code) in the main model.
The pros in loading that 2nd model are less code/easier to maintain.
The cons are overhead of loading a 2nd model.
Are my fears of overhead valid? I’m a non CS person and just wondering what’s the best practice here.
thanks,
tim
Don’t Repeat Yourself. If you do you will only make your life a lot harder than it should have been when it comes to maintaining your code down the line. The principles of good OOP encourage you to create classes with a specific area of responsibility, and using that class to handle the situations it was built for. Duplicating functionality in class X into class Y violates this principle. If class Y needs to do something class X does, then this means that either class Y needs to talk to an instance of class X, or class Y should inherit from class X.
It would also be a micro-optimization at best. The performance hit for loading the other class should be negligible, certainly nothing worth worrying about.