User Tools

Site Tools


programming_general:object-orientation_fundamentals

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
java:object-orientation_fundamentals [2020/09/11 21:51] – [Why object-orientation?] mithatprogramming_general:object-orientation_fundamentals [2020/09/11 22:05] – ↷ Page moved from general:object-orientation_fundamentals to programming_general:object-orientation_fundamentals mithat
Line 51: Line 51:
  
 ====  Encapsulation and protection ==== ====  Encapsulation and protection ====
-As a user, I change the state of the oven by engaging one or more of the operations in the oven's interface. In other words, I'm not expected to open up the oven and hack at its guts to make the  magnetron work at maximum level for whatever time I want. As a user of the oven, I don't need to know how a magnetron or the power supplies work, and if I am a typical user I don't really care. I only need to know what changes in state to expect from the "cook 1 minute" or "add 30 seconds" operations.+As a user, I change the state of the oven by engaging one or more of the operations in the oven's interface. In other words, I'm not expected to open up the oven and hack at its guts to make the  magnetron work at maximum level for whatever time I want. As a user of the oven, if I am a typical userI don't really care. I only need to know what changes in state to expect from the "cook 1 minute" or "add 30 seconds" operations.
  
-Along the same lines, when I change the clock's setting by pushing the buttons to engage the "set current time" operation, the innards of the oven takes care of all the details of getting the data to the right place, etc. As a user, I don't need to know exactly how it does it, and again, I probably don't care. I only need to know what to expect from the operation.+Along the same lines, when I change the clock's setting by pushing the buttons to engage the "set current time" operation, the innards of the oven takes care of all the details of getting the data to the right place, etc. As a user, I don't need to know exactly how it does it. I only need to know what to expect from the operation.
  
 This idea of "not caring about how it works---I only need to know what it does" is the essence of **encapsulation** (literally, "to place in a capsule") in object design. Someone who wants to use the microwave oven only needs to know what to expect when using the public-facing interface. This idea of "not caring about how it works---I only need to know what it does" is the essence of **encapsulation** (literally, "to place in a capsule") in object design. Someone who wants to use the microwave oven only needs to know what to expect when using the public-facing interface.
Line 59: Line 59:
 In fact, even if I wanted to get at, for example, magnetron inside or directly change the clock's setting, I couldn't---at least not without a whole lot of pain and bother. The oven's insides are normally protected against public fiddling by screws and scary labels. And assuming that I actually manage to open it up, I would still need to know, say, where the clock module is, what its electronics parameters are, and a whole bunch of other hackery. No thanks. It's better to just use the designed-in public-facing behavior---its interface---than get a PhD in microwave oven design. In fact, even if I wanted to get at, for example, magnetron inside or directly change the clock's setting, I couldn't---at least not without a whole lot of pain and bother. The oven's insides are normally protected against public fiddling by screws and scary labels. And assuming that I actually manage to open it up, I would still need to know, say, where the clock module is, what its electronics parameters are, and a whole bunch of other hackery. No thanks. It's better to just use the designed-in public-facing behavior---its interface---than get a PhD in microwave oven design.
  
-The Keeping someone out of stuff they should not be allowed to access is called **protection** or sometimes **information hiding**. In many (but not all) languages, properly hiding things the user has no business getting into is considered part of encapsulation.+Keeping someone out of stuff they should not be allowed to access is called **protection** or sometimes **information hiding**. In many (but not all) languages, properly hiding things the user has no business getting into is considered part of encapsulation.
  
 ==== Objects ==== ==== Objects ====
Line 80: Line 80:
 ==== Prototype-based object-orientation ==== ==== Prototype-based object-orientation ====
  
-There is another kind of object-orientation called **prototype-based object-orientation** or **prototype-based programming**. This is the kind of object-orientation used in JavaScript and some other languages.((C++, Java, C#, and PHP support only class-based object-orientationJavaScript and Ruby are inherently prototype-basedObjective-C is class-based but lets you do prototype-based programming.)) I will leave it to you to get your Google on and learn more about prototype-based object-orientation if you want.+There is another kind of object-orientation called **prototype-based object-orientation** or **prototype-based programming**. This is the kind of object-orientation used in JavaScript and some other languages.((C++, Java, C#, and PHP support only class-based object-orientationJavaScript and Ruby are inherently prototype-based, though "modern" JavaScript (ES6 and beyond) can emulate class-based inheritance. Objective-C is class-based but lets you do prototype-based programming.)) I will leave it to you to get your Google on and learn more about prototype-based object-orientation if you want.
  
 ==== Ovens and code ==== ==== Ovens and code ====
programming_general/object-orientation_fundamentals.txt · Last modified: 2020/11/15 00:03 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki