Instead of creating an instantiation of an object in the application scope and then creating references to it, you want to instatiate a new object via createObject() each time.
As far as whether you want to expose internal data directly or not, I suppose that's up to you, but what I know about object design tells me that you want to be very careful about that. Basically, if you can read a variable, you can typically write a variable, which means that you can break an object by assigning nonsensical values to internal variables. This is not so much an issue when it's just you using it for one project, but when you are using a class for a number of projects, especially if you are sharing with other people, and ESPECIALLY if you have a lot of inheritance (which can dramatically change what a valid value is for a variable) (nice alliteration, eh?) you want to avoid exposing any critical values directly -- you want to do things like getData() and setData() where the setter does validation on the value passed in and returns a boolean indicating success (or something like that). I probably woulnd't even ever expose the data as a recordset. If I wanted to return all data from a data storage object (like Question or Answer) I'd return it as a plain structure. If I was returning data from a list/array/group object (like QuestionGroup or AnswerGroup) I would return an array of references to data storage objects. That way, internal ways of doing things can change, but it's fairly simple to translate internal data stored in whatever form to structures or arrays of references, so your external appearance (what's seen from outside the Blackbox) never has to change. Hmm. I think I took too many courses involving object design, eh? -- Ben Doom Programmer & General Lackey Moonbow Software, Inc : -----Original Message----- : From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] : Sent: Thursday, April 03, 2003 10:10 AM : To: CF-Community : Subject: RE: OOCF, CFCs and the questionnaire app : : : Ok gotcha that sounds like a good idea. I seem to be running into : implementation problems now. I am having a hard time figuring : out how best : to leverage the CFCs. So far I am looking at creating an instance of each : major CFC in the application scope in the Application.cfm. That : way I have : the class available where ever I am. Then I can create instances : from that. : So say something like: : : user = createObject('component','user'); : : currentUser = user.getUser('1'); : : Now current user is just the query object that's returned. Not the actual : user right? This is whats confusing me I think. See I want a : user object. : It should have the properties of cFirstname, cLastName, cEmail, cUsername, : cPassword. Now when you first call the createObject() function I : would like : to initialize these, and then use getters and setters to affect them. I : can't seem to see how to make it work like I want though. I was thinking : that by using 'this' maybe. I remembered something about the code you put : in the component, but not in a function, will execute when you first : instantiate the object, so a constructor of sorts. Kewl, but how : do I deal : with variables? Do I necessarily want all of my properties to be private, : so instead of being currentUser.cFirstName, I want to do : currentUser.getFirstName()? Do I have to do a currentUser.setFirstName(); : first, or is it ok to have a single method that does the pull and : then dumps : the values into the variables? : : : Timothy Heald - setting the world on fire, one brain cell at a time. : Overseas Security Advisory Council : U.S. Department of State : : "that the free Constitution, which is the work of your hands, may be : sacredly maintained" - George Washington, Farewell Address 1796 : : : : -----Original Message----- : From: Ben Doom [mailto:[EMAIL PROTECTED] : Sent: Wednesday, April 02, 2003 5:00 PM : To: CF-Community : Subject: RE: OOCF, CFCs and the questionnaire app : : : I would create a QuestionGroup object, which contains an array of : questions. : Then, you could populate it by category, who posed it, who : answered it, etc. : So, in theory, you could select all questions about food posed by BenB and : answered by Candace. You could also simply populate it with : everything, or : nothing, or whatever. Kind of a recordset for questions. : : I would also create types Answer and AnswerGroup so you could do the same : thing. A QuestionGroup contains a Question which contains an AnswerGroup : which contains specific Answers to that Question. : : Make sense? : : : -- Ben Doom : Programmer & General Lackey : Moonbow Software, Inc : : : -----Original Message----- : : From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] : : Sent: Wednesday, April 02, 2003 2:10 PM : : To: CF-Community : : Subject: OOCF, CFCs and the questionnaire app : : : : : : Ok, : : The boss and I are using the questionnaire app to expand : our skill set : : some during lunch. We are looking at how to objectify it, what : methods to : : have, what might be good to break into a web service. During : this process : : several questions have arisen. : : : : 1. Why the hell won't CF 5 close my CFMX tags like cfcomponent or : : cffunction? I know I am being lazy but so what. : : : : 2. How do you break up things that deal with one of an object : : (getQuestion()) and deal with several instances at once : : (getQuestionsByCat())? Say I want to list all the questions in a : : category. : : Is that properly a method of the question object, or do I need : a category : : object? : : : : So far we have decided on the following objects and methods : : : : User : : newUser - constructor, will be used after login to create as a : : session object that will go through the site with the users credentials, : : basically just a db query to pull the users info and check the login : : : : getUser - used to look up users, say in an address book : : like manner : : : : setUser - input new user info, used for registration. : Should this : : be broken up more in to things like setAddress, setEmail? Also can your : : override functions in CFMX? I guess I could get the same effect just by : : doing some conditional work inside the method right? : : : : addQuestion - enter a new question. Question would still : : need to be : : approved by an administrator - calls question constructor?? : : : : Administrator - extends user : : newAdministrtator - constructor - called if the user has admin : : rights. What's the way to make this happen in the newUser constructor : : automatically? : : : : approveQuestion - Approve a user entered question : : : : approveUsers - Approve a new user application. Figured : : make it so it : : can handle many users at once. Should it be for a single user : : and then just : : something you do many times? : : : : getNewUsers - Gets the listing of new user application : : : : Question : : newQuestion - question constructor : : : : getQuestion - pulls a specific question : : : : getAnswers - pulls the answers for a specific question : : : : getAnswersByUser - pulls a users answers : : : : getQuestions - list of all questions : : : : getQuestionsByCategory - pulls questions by category : : : : answer - answer a question : : : : setCategory - set the questions category : : : : setQuestion - edit/enter a question : : : : I guess that's about it. See anything I am missing? Am I : : putting anything : : in the wrong place? : : : : Timothy Heald : : Overseas Security Advisory Council : : U.S. Department of State : : "that the free Constitution, which is the work of your hands, may be : : sacredly maintained" - George Washington, Farewell Address 1796 : : : : : : : : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=5 Subscription: http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=5 Your ad could be here. Monies from ads go to support these lists and provide more resources for the community. http://www.fusionauthority.com/ads.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.5