For example, a puppy and a dog might be treated differently at a pet camp. The state of an object is defined by the data in the object’s attributes fields. When objects are instantiated, individual objects contain data stored in the Attributes field. Attributes are defined in the Class template. N/AĪttributes are the information that is stored. Behaviors are methods the object can undertake. The state of an object is defined by data: things like names, birthdates, and other information you’d want to store about a dog. This may cause confusion because objects can be declared without a class template in JavaScript, as shown at the beginning. In JavaScript, objects are a type of variable. The constructor runs name & birthday arguments, and assigns values. We can also create objects like Rufus that fit under the broad class of Dog but do not fit under either HerdingDog or TrackingDog. These have the inherited behaviors of Dog ( bark()) but also behavior unique to dogs of that subtype.įinally, we create objects of the HerdingDog type to represent the individual dogs Fluffy and Maisel. We then create two child classes of Dog, HerdingDog and TrackingDog. The Dog class is a generic template containing only the structure of data and behaviors common to all dogs as attributes. The diagram below represents how to design an OOP program by grouping the related data and behaviors together to form a simple template and then creating subgroups for specialized data and behavior.
0 Comments
Leave a Reply. |