I was doing a lecture for the first year C# course and was talking about design with objects. From the business point of view I'm trying to get a seqeuence of design actions together into a little train of thought. The sequence goes like this:
- Identify an object in your system (for example customer).
- Identify a property of the object (for example customer name).
- Decide how you are going to store that property (use a string)
- Add the property and make it private (then nobody can fiddle with it)
- Decide if you need to be able to change it. If you do, add a set method with error checking. Make this public.
- Add a get method for your property. Make this public.
- Decide if you need to be able to set this value when the object is created. If you do, add it to the constructor.
- Repeat for all the other properties (address, phone number, credit limit etc).
- You then have a nice shiny object which can hold things and a bunch of methods that describe what it can do. Take all the methods and slap them into an inferface. Make the object implement the interface and manage all the objects in terms of that interface. It is now a component.
I advised the students to look at objects around them and consider how they would be managed in this way, what in them could/should be changed by a program and the data types to be used for each. You can do this on anything. Bus stops, tooth brushes, pens, cheese. I recommend it as a form of mental exercise in object design. You should also think of questions to ask your customer: "Do you need to store the number of bristles on your toothbrush?" for example....