Object-oriented programing creates objects as classes. The objects have data and functions. The objects represent something in the real
world, and functions act on the object to represent things that would occur in
the real world. For example, Toy and Dog
from exercise one are objects and the Dog can play with Toy, just like a real
dog.
When creating objects, an easy way to start is to brainstorm
different properties of the object. The
noun will be the class name, the adjectives that describe the object will be the
attributes, and the verbs will be the operations or methods. For example, a child would have class name
Child, attributes age, gender, height etc., and have methods play, cry, grow,
etc.
For the most part, I understand object-oriented
programing. I struggled a little with
defining classes in CSC108, but I feel like exercise one and the labs for this
course have helped me better understand the concepts. I like how the classes mirror real objects
because it is easy to see how clients can apply the classes. For example, you make a class Calendar with attributes
day, week, month, etc. and methods like adding and removing events from the
calendar. This class is exactly the same
as a tangible calendar and a client could use Calendar in the same way they
would use a paper calendar.
No comments:
Post a Comment