Im new to thinking in an OO Fashion. im from a db background so procedural and functional methodologies are all i know.
Im writing a basic photo album in c# and asp.netand want it to be as Object Oriented as possible, purely for learning purposes.
Currently the objects i have are:
Photo. will contain a photo, description of photo and a path to the physical file.
Album. Can contain many photos.
User. Able to upload, delete photos.
One thing i am not sure of is in relation to uploading/deleting photos. Is this a method in the photo class? is it a method in the user class, as users delete/upload photos? Or is there a third class that im missing?
Loading
Rob CollinsPosted Oct 26, 2010, 1:03 PM
First I'd ask, what do you intend to do with the photos in the album? Just display them? If so, I'd be inclined to make an 'Album' object. And within the Album object have a 'collection' or 'list' of the photos. Then Add/Delete etc are methods in the Album object operating on the collection or list. Yes the collection or list are like an array of objects but its built in functionality rather then making a custom class.
Now, if on the other hand, you intend to actually 'process' the photos in some way (IE have methods that run on them to change their color or affects or watermark or whatever), then I would probably put in a 'Photo' object. That is, if you have more actions that can be done on the photos that relate to 'parts' of the photos rather then the whole photo. That way you can encapsulate that functionality within the photo class.
I'm not a fan of making too many objects. Not that you have a big object set just yet, but, I like to keep things simple. My philosophy is that just because the ability exists I don't necessarily have to use it. Like inheritance. I think one can get really carried away with it and end up with their hands tied.
When I think about what to create custom classes for, it takes me a while. I make circle diagrams and connect the circles and list functionality and then I do it again and again. To me its the most critical aspect of software design. Good architecture.