> I'm looking for someone to give me a hug and tell me everything will > be ok. I'll go ahead and do this: *hug*
Regarding your topic: I think you are getting a little paranoid here. Yes high coupling is something you want to avoid. Coupling itself however is not your enemy, it's how you write actual applications that do things. If you are writing an Image handling class and you already have a File class and you notice that you only need very little of File inside of Image you might want to not extend or depend on File and just risk some minor dupplication. This allows you to decouple File from Image. When however you are writing a database depended application you have to accept that field names are something that will pop up all through your application. You could probably write huge config files and only refer to field names by their configuration value so if you change them once you would just have to change the config file. However this is not the cake way of conventions over configuration. What you really want to do is to just use your field names freely throughout the project and in case on of them ever changes, run a quick project-wide search & replace. If the field name is too generic some manually checking might be required. However first of all try to avoid changing field names. These days I spend more time than I used to when it comes to naming things and deciding on structures to use. Because I know that something that is well named and designed in the first place will be less likely to frustrate me later on causing me to change it. Now being scared of rewriting bad code or revising bad naming decisions is bad too, after all this is how true beauty is created, but a little planning can sometimes get you very far. > Can anyone suggest alternatives, or at least stroke my forehead and > tell me everything will be ok! Hope I just did that ; ). -- Felix -------------------------- http://www.thinkingphp.org http://www.fg-webdesign.de Sonic Baker wrote: > Hi there, > > I'm looking for someone to give me a hug and tell me everything will > be ok. > Thinking in terms of low coupling of classes again, it struck me that > passing your applications method parameters as associative arrays may > be a step in the wrong direction. For example, I have a cake component > to which I pass the result of a $this->Model->find(); The result is of > course an associative array. Inside the component, I extract the keys > I want and ignore the rest. So I may take $params['Post']['title'] > and ignore $params['Post']['comment']. > However, if I happen to change the field names in the database table, > the resulting array keys will also change. This means that not only > will this change affect my Model, but it will also affect anything > which is expecting the field name as a key. So if I change a field in > the `posts` table from 'title' to 'some_title', my component will > still be expecting $params['Post']['title'] and so, this part of the > system is somewhat tightly coupled. > The only solutions I can think of are: > (1) To avoid passing arrays as params and pass them as variables > instead. This may lead to methods expecting a long list of parameters > though. This can be ugly and confusing to the reader. > (2) Set up the params array to the expected structure before > passing it to the component. However this still means a change in the > database table will ripple through to the controller. > > Allowing the component to access the model itself will mean that the > component is still coupled to a Model. > > Can anyone suggest alternatives, or at least stroke my forehead and > tell me everything will be ok! > > Cheers, > > Sonic > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
