What's so great about objects?Objects work so well because they act just like real life objects- objects have properties and methods. So if we were talking about a lamp, a property of it may be its height or width, say 12cm. A method of it may be to shine (an action). And when it's shining, its brightness property would be of a greater value than when it wasn't.
We define a custom object "person," then add to it its own properties and method afterwards. In this case, the custom method merely initializes two more properties.
While using the new operator or literal notion to create a custom object is both simple and logical, the biggest shortcoming is that the result is NOT reusable- we cannot easily initialize different versions of the created object. For example with the first demonstration above, if the person's name is not "Tim Scarfe", we would need to redefine our entire object just to accommodate this change.
Post a Comment
silahkan berkomentar, kritik dan saran yang membangun adalah harapkan kita semua !