Code encapsulation and include()
Posted: Mon Aug 15, 2005 10:05 am
Hello,
I need some opinions on code encapsulation and using included files. I'm working on a user-based project. Each time that a user logs in, a new object (instance of the "user" class) is created. That class contains all the attributes about the user (username, date joined, age, location, etc) and it has all the functions that a logged in user needs. This class is stored in a file called user.class.php. I also have a file called functions.php, which contains all the functions that everyone needs, logged in or not (stuff like simplified SQL_query function, various calculation functions, etc.). Herein lies my question: when is it appropriate to put code into these files? I'll give an example: I have a private messaging system, and my colleague put the function that send messages into the user.class.php, used include() to include that file and called the function as $user->send_message(). I started thinking that it was a little inappropreate because it's such a specific function, that there's no way it can be reused. Therefore, it should be pout with the private messaging system, not with the user class. What are you opinions on this case, and in general? When is it appropreate to put specific functions into a class?
Thanks.
I need some opinions on code encapsulation and using included files. I'm working on a user-based project. Each time that a user logs in, a new object (instance of the "user" class) is created. That class contains all the attributes about the user (username, date joined, age, location, etc) and it has all the functions that a logged in user needs. This class is stored in a file called user.class.php. I also have a file called functions.php, which contains all the functions that everyone needs, logged in or not (stuff like simplified SQL_query function, various calculation functions, etc.). Herein lies my question: when is it appropriate to put code into these files? I'll give an example: I have a private messaging system, and my colleague put the function that send messages into the user.class.php, used include() to include that file and called the function as $user->send_message(). I started thinking that it was a little inappropreate because it's such a specific function, that there's no way it can be reused. Therefore, it should be pout with the private messaging system, not with the user class. What are you opinions on this case, and in general? When is it appropreate to put specific functions into a class?
Thanks.