RE: Why do I need getters/setters?
> But I was lookin at Joe's legacy samples ... I wouldn't read too much into samples. I haven't looked at the sample in question, but it may not be a complete application. Dave Watts, CTO, Fig Leaf Software http://www.figleaf.com/ Fig Leaf Software provides the highest caliber vendor-authorized instruction at our training centers in Washington DC, Atlanta, Chicago, Baltimore, Northern Virginia, or on-site at your location. Visit http://training.figleaf.com/ for more information! ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;203748912;27390454;j Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:308035 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: Why do I need getters/setters?
>Well, the example I created was pulled right out of my ... imagination. But >if you create different object instances for each user, and store those in >each user's session, the fact that you have the same structure for each of >those instances doesn't matter at all. > But I was lookin at Joe's legacy samples and I see he has a Contact.cfc and ContactManager.cfc in his model. And in his controllers he has a ContactManagerController.cfc. It has this line: So does model glue automatically take care of it for you? How would this be thread safe? There isn't a reference to session anywhere I can find. Thanks Dave! Will ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;203748912;27390454;j Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:308033 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
RE: Why do I need getters/setters?
> One thing that's messin' up my head is, these cfc's are > usually stored in application scope. This information looks > more like personalized info, which is usually stored in > session scope. > > I'm not understanding how info doesn't get crossed up between > users. lol! Well, the example I created was pulled right out of my ... imagination. But if you create different object instances for each user, and store those in each user's session, the fact that you have the same structure for each of those instances doesn't matter at all. Dave Watts, CTO, Fig Leaf Software http://www.figleaf.com/ Fig Leaf Software provides the highest caliber vendor-authorized instruction at our training centers in Washington DC, Atlanta, Chicago, Baltimore, Northern Virginia, or on-site at your location. Visit http://training.figleaf.com/ for more information! ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;203748912;27390454;j Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:308027 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: Why do I need getters/setters?
> > > > > > > > > > Thanks dave! Oops Dave (ahemm) One thing that's messin' up my head is, these cfc's are usually stored in application scope. This information looks more like personalized info, which is usually stored in session scope. I'm not understanding how info doesn't get crossed up between users. lol! Thanks, Will ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;203748912;27390454;j Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:308025 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
RE: Why do I need getters/setters?
> I'm just not understanding why I'd need a getter and a setter > in my cfc. > > ... > > What is the value of keeping each value in its own variables > scoped variable? Where does it come in handy? Where are you > supposed to use it? As many people have mentioned, you don't need getters and setters. However, they do provide a potential value. If you're creating a value object - an object whose sole purpose is to map to a specific database record, generally - you don't want to embed business logic in that object. So, you could create something like this: Those variables, being public, could then be manipulated by users of the value object: ... And, honestly, in many environments that might be sufficient. However, what if you want to provide basic validation within your value object? Or what if you want to ensure that the values you retrieve from your value object are the right datatype? You won't be able to do that with public variables; instead, you'd need getters and setters: ... In the above example, the object is in charge of setting its own internal values, and can validate inputs to do so. Now, honestly, in many cases people don't bother doing that, or there aren't any meaningful validation tests to perform, so people build the simplest possible getters and setters, and they don't do anything beyond providing encapsulation. But still, this can be valuable, as you can add validation at any time without breaking the use of those components. The value of getters and setters is a little more obvious in languages like Java and ActionScript 3, which let you provide method names that can be invoked as if they were the actual properties themselves: private var name:String; private function set name(newName):String { name = newName; } myObj.name = "Dave"; // this would call the method described above If you want to provide the encapsulation, but don't want to bother writing the code, there are a couple of approaches you can take. In CF8, you can use onMissingMethod to write one generic method that would respond to calls for specific getters and setters that don't actually exist. Or, better yet (in my own personal opinion) you could use one of the many, many code generators that let you point to a database table and generate value objects (and DTOs, gateway/assembler objects, etc). Since you can use these to reduce your time spent to nearly zero, there isn't much reason not to. Dave Watts, CTO, Fig Leaf Software http://www.figleaf.com/ Fig Leaf Software provides the highest caliber vendor-authorized instruction at our training centers in Washington DC, Atlanta, Chicago, Baltimore, Northern Virginia, or on-site at your location. Visit http://training.figleaf.com/ for more information! ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;203748912;27390454;j Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:308010 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: Why do I need getters/setters?
> Just to be difficult, You mean like this: -- s. isaac dealey ^ new epoch isn't it time for a change? ph: 617.365.5732 http://onTap.riaforge.org/blog ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;203748912;27390454;j Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:308007 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: Why do I need getters/setters?
Thank you all for the info. It's most helpful! Will ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;203748912;27390454;j Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:307989 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: Why do I need getters/setters?
As others have pointed out, getters and setters are there for encapsulation. For example, if you have a getPrice() method on a Product, right now it might return just a price instance variable. But later you may need to add in much more complex logic such as tiered pricing for certain customers, sales, etc. If you weren't using a getter but were instead directly accessing the "price" instance variable, you'd have problems. That said, in general getters and setters are evil and I feel they are overused in may cases. They promote a more procedural programming approach and fly in the face of good OOP. One should normally not be asking an object for data, but should be telling the object to DO something based on its data. Getters and setters do offer encapsulation, but they are actually only slightly less brittle than direct variable references. The more one interrogates an object to get at its data, but more one drifts towards a procedural approach. OO is about telling objects to do something with the data they contain, not asking them for their data. This is the root of the saying "Tell, don't ask" in OOP. In practice about the only time I use a getter is if I have an object and I am actually outputting its data to the view. And even that is a potentially strong argument for allowing objects to render themselves instead (through a composed rendering object of course, the object itself shoudn't know or care about how it may eventually be presented). I'm still on the fence in that regard but the idea has a number of advantages. That might be a subject for another thread though. Regards, Brian On Mon, Jun 23, 2008 at 12:46 PM, Will Tomlinson <[EMAIL PROTECTED]> wrote: > I'm just not understanding why I'd need a getter and a setter in my cfc. > > My app works just fine without setting anything in the variables scope of > my cfcs. You submit a form, it adds the values to my db. You run a query and > get all the values back out. > > What is the value of keeping each value in its own variables scoped > variable? Where does it come in handy? Where are you supposed to use it? > > Here's a few lines from the legacy samples. > > > > > > output="false"> > > > > Guess I'm missing something since I don't have an OO background. Googled a > little but still confused. > > Thanks, > Will > > ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;203748912;27390454;j Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:307979 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: Why do I need getters/setters?
Will, Many of the ideas within OO are to promote encapsulation, easy reuse, and increased maintainabilty. In your example, it may be much easier to submit a form to a page that takes those values and adds them to the database. But for example lets say you are storing a "customer", and that you must ensure that there are no illeagal characters in their name. In your example, this can easily be done inline in the page, but what if you have multiple places where a customer can be entered? What about the SQL necessary to store this customer? Using OO, each of these operations is in exactly one place, and all your other code leverages that single place. This is one of a myrid of problems that OO attempts to solve. You gain flexibility and maintainability but at the cost of an increased learning curve and additional complexity. HTH, Rich ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;203748912;27390454;j Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:307978 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: Why do I need getters/setters?
Just to be difficult, >>> You cannot set or get the variables scope directly, so you need the getter and setter to do this. >>> Actually, in Coldfusion you can. Of course, you have to reference them somewhere else in you CFC if you want to access them from outside your CFC, but it doesnt HAVE to be specific getter and setter methods. Using G/S methods is just the right way to do it, from a best practices standpoint. =] -- Alan Rother Adobe Certified Advanced ColdFusion MX 7 Developer Manager, Phoenix Cold Fusion User Group, AZCFUG.org ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;203748912;27390454;j Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:307977 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: Why do I need getters/setters?
One word: encapsulation. The variables scope allows you to have instance data that is specific to a particular instantiation of an object. So does the "this" scope, but this is less preferred, as it makes the properties directly available outside the CFC. You cannot set or get the variables scope directly, so you need the getter and setter to do this. It sounds like maybe you are talking about singletons, where you only have one instance of an object. In this case you don't need getters and setters, since you are not setting instance data, other than perhaps a datasource name, which can be set the init method. In your example below with the LastName getter and setter, you might have a Person class which has those getters and setters. So you might do this: #person1.getLastName()#, #person2.getLastName()# -- outputs "Jones, Smith" Now, you might want to get fancy and "do something" with the last name, for example remove any commas so it won't break a cfmail. You can then do this in your getter: This will be done for all and any last names, and you never have to worry about it again. -- Josh - Original Message - From: "Will Tomlinson" <[EMAIL PROTECTED]> To: "CF-Talk" Sent: Monday, June 23, 2008 9:46 AM Subject: Why do I need getters/setters? > I'm just not understanding why I'd need a getter and a setter in my cfc. > > My app works just fine without setting anything in the variables scope of > my cfcs. You submit a form, it adds the values to my db. You run a query > and get all the values back out. > > What is the value of keeping each value in its own variables scoped > variable? Where does it come in handy? Where are you supposed to use it? > > Here's a few lines from the legacy samples. > > > > > > output="false"> > > > > Guess I'm missing something since I don't have an OO background. Googled a > little but still confused. > > Thanks, > Will > > ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;203748912;27390454;j Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:307976 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
RE: Why do I need getters/setters?
The theory behind getters and setters is abstraction. You are not "supposed" to deal with the data directly nor are you "supposed" to know how the data is stored and how the object works. You create an object and let it do the work for you. Getters and Setters hide implementation details of the object from the user. They don't always have to be a simple example. What about a getter called getNextToLastItem(). Does the object store the items as a list, an array, or a struct? If you use the getter, you don't have to know, nor will your code become dependant upon the implantation of the CFC. There are several theories on getters and setters, and not everyone agrees on their usefulness. I've found some of the more advanced levels of Object Orientedness seem to lose their value, the smaller your programming team is. For instance, if you are responsible for writing the CFC AND using it, you have to know its inner workings anyway so abstraction might not be that big of a deal to you. (Not to say it still couldn't provide usefulness at some level). Regardless, design patters (like getters and setters) do not exist because your code will not work otherwise. They exist to accommodate and encourage good coding practices. YMMV. ~Brad -Original Message- From: Will Tomlinson [mailto:[EMAIL PROTECTED] Sent: Monday, June 23, 2008 11:46 AM To: CF-Talk Subject: Why do I need getters/setters? I'm just not understanding why I'd need a getter and a setter in my cfc. ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;203748912;27390454;j Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:307975 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
RE: Why do I need getters/setters?
I think the primary reason for using get/set is to extract the specific variable from the larger picture. This way, if something even happens to your code and you change the source location of the variable's value, you only have to change it in one place. I personally don't use get/set as I don't see much value in it, but then I'm self taught and OO isn't really a big concern for me ATM. I can easily see this changing over time though. -Original Message- From: Will Tomlinson [mailto:[EMAIL PROTECTED] Sent: Monday, June 23, 2008 11:46 AM To: CF-Talk Subject: Why do I need getters/setters? I'm just not understanding why I'd need a getter and a setter in my cfc. My app works just fine without setting anything in the variables scope of my cfcs. You submit a form, it adds the values to my db. You run a query and get all the values back out. What is the value of keeping each value in its own variables scoped variable? Where does it come in handy? Where are you supposed to use it? Here's a few lines from the legacy samples. Guess I'm missing something since I don't have an OO background. Googled a little but still confused. Thanks, Will ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;203748912;27390454;j Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:307974 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: Why do I need getters/setters?
Short answer... You don't You CAN build CFCs pretty much anyway you want to. Frankly, in CF if it works, and you like how it works, then it's perfect. Using getters and setters is really more of an OO habit than anything else in CF. -- Alan Rother Adobe Certified Advanced ColdFusion MX 7 Developer Manager, Phoenix Cold Fusion User Group, AZCFUG.org ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;203748912;27390454;j Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:307971 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4