Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 01-08-2003, 08:01 AM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,475
sde is on a distinguished road
class theory

since i've pretty much taught myself most of what i know about classes, i thought i'd ask here about the logic on this specific issue.

i'm making a class called Agent.

functions within this class include:

createAgent() -enters new agent in the system
searchAgent($string) -searches agents and returns array of agent ids

setAgent($agent_id) -sets all agent properties
editAgent($agent_id) -edits agent properties

when i create a new Agent object, it really relates to just 1 agent. so if my searchAgent() function returns 5 Agent IDs, then 5 new Agent objects will be created.

here is my question .. should createAgent() and searchAgent() be in my Agent class? those 2 functions deal with ALL Agents, and setAgent() and editAgent() deal with 1 single agent.

if this doesnt' make sense.. i'll try again.
sde is offline   Reply With Quote
Old 01-11-2003, 12:14 PM   #2 (permalink)
technobard
Centurion Nova Prime
 
technobard's Avatar
 
Join Date: May 2002
Location: Oak Park, IL (USA)
Posts: 285
technobard is on a distinguished road
If the function/method deals with only 1 agent, I'd make it part of the Agent class. It acts on variables that are part of the same class.

For the functions/methods that act on all or multiple agents, I'd create a second class that contains an array of Agent objects--let's call it Agency.

createAgent is really just a wrapper for calling Agent's constructor. Something like: $var = new Agent($stuff);

So, I'd probably make createAgent part of Agency. That way it would both create the new Agent and then add it to the array of Agent objects.

Of course, there is nothing that requires you to create Agency at all. You could handle the array of Agent objects and any other functionality outside of a class.

Hope this helps.
technobard is offline   Reply With Quote
Old 01-11-2003, 12:48 PM   #3 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,475
sde is on a distinguished road
thanks, that is the logic i needed to read. since php executes once only to output html, it probably doesn't make sense to use multiple agents. i can just keep resetting the current agent object. and that's what i'll do =)
sde is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
c++ class question saiz66 Standard C, C++ 3 06-09-2004 07:43 PM
to put data methods inside class or not? sde Java 2 05-25-2004 04:09 PM
pointer to function with class? Kportertx Standard C, C++ 5 04-11-2003 05:12 AM


All times are GMT -8. The time now is 10:56 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting