programming_general:object-orientation_fundamentals
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
java:object-orientation_fundamentals [2020/09/11 21:38] – [Why object-orientation] mithat | programming_general:object-orientation_fundamentals [2020/09/14 01:14] – mithat | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Object-Orientation Fundamentals ====== | ====== Object-Orientation Fundamentals ====== | ||
+ | ------------------ | ||
+ | ===== Why object-orientation? | ||
+ | **Object-oriented programming** came about to support **object-oriented analysis and design** (OOAD). | ||
+ | But why objects? | ||
- | ===== Why object-orientation? ===== | + | OOAD was created to try to solve some of the issues involved in designing and managing large applications. |
- | Object-oriented | + | |
+ | ------------------ | ||
+ | |||
+ | It represents a shift in the way you typically approach a problem using procedural/ | ||
+ | |||
+ | ------------------ | ||
+ | |||
+ | In object-oriented | ||
+ | |||
+ | ------------------ | ||
+ | |||
+ | While it is possible to analyze | ||
- | OOAD came about to try to solve some of the issues involved in designing and managing large applications. It represents a shift in the way you typically approach a problem using procedural/ | + | So, OOAD facilitates a higher level of modular |
- | While it is possible to design systems (i.e., application) using this approach and then implement the design in any language, the implementation is made much easier and more robust when the language has the necessary support for defining and using objects. Such a language is an object-oriented language. | + | ------------------ |
- | OOAD facilitates a higher level of modular thinking and especially with an object-oriented language also allows for more effective project management, especially across a team of developers. | ||
===== Object-oriented concepts ===== | ===== Object-oriented concepts ===== | ||
Line 22: | Line 36: | ||
We next explore each of these in the context of an object from the real world: a microwave oven. | We next explore each of these in the context of an object from the real world: a microwave oven. | ||
+ | |||
+ | ------------------ | ||
==== State ==== | ==== State ==== | ||
Line 33: | Line 49: | ||
All these attributes, which can be defined in terms of data, collectively define the oven's state. | All these attributes, which can be defined in terms of data, collectively define the oven's state. | ||
+ | |||
+ | ------------------ | ||
==== Behavior ==== | ==== Behavior ==== | ||
Line 44: | Line 62: | ||
These operations are ones that happen to be public-facing (i.e., operations a user can engage). We call this public-facing behavior (i.e., the operations a user can engage) the oven's **interface**. There might also be operations that go on inside the oven that the user will never be aware of to support the oven's functioning. These are not part of the oven's interface but are important behaviors all the same. | These operations are ones that happen to be public-facing (i.e., operations a user can engage). We call this public-facing behavior (i.e., the operations a user can engage) the oven's **interface**. There might also be operations that go on inside the oven that the user will never be aware of to support the oven's functioning. These are not part of the oven's interface but are important behaviors all the same. | ||
+ | |||
+ | ------------------ | ||
==== 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" | + | 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 user, I don't really care. I only need to know what changes in state to expect from the "cook 1 minute" |
- | Along the same lines, when I change the clock' | + | Along the same lines, when I change the clock' |
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" | 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 fact, even if I wanted to get at, for example, magnetron inside or directly change the clock' | In fact, even if I wanted to get at, for example, magnetron inside or directly change the clock' | ||
- | 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 61: | Line 85: | ||
Object-oriented languages are languages that let you create self-governing entities. Such self-governing entities are called **objects**. | Object-oriented languages are languages that let you create self-governing entities. Such self-governing entities are called **objects**. | ||
- | To put it another way, an object is a program entity that encapsulates state (via attributes) | + | To put it another way, an object is a program entity that encapsulates state and behavior for some meaningful abstraction. |
+ | |||
+ | ------------------ | ||
==== Class-based object-orientation ==== | ==== Class-based object-orientation ==== | ||
{{: | {{: | ||
- | I have a Farberware 4241 microwave oven in my office. It's small, but it gets the job done. There is a factory somewhere making these by the thousand million. They make all the Farberware 4241s from a master plan, a plan that defines what the Farberware 4241 //is//. In object-oriented design terminology, | + | I have a Farberware 4241 microwave oven in my office. It's small, but it gets the job done. There is a factory somewhere making these by the thousands. All the Farberware 4241s they make come from a master plan: a plan that defines what the Farberware 4241 //is//. In object-oriented design terminology, |
Languages that support **class-based object-oriented programming** let you define classes at a very high level. Once you've defined a class you can then create **instances**: | Languages that support **class-based object-oriented programming** let you define classes at a very high level. Once you've defined a class you can then create **instances**: | ||
Thus my oven is an instance of a Farberware 4241, and you might say the Farberware factory spends it's entire day instantiating 4241 ovens. | Thus my oven is an instance of a Farberware 4241, and you might say the Farberware factory spends it's entire day instantiating 4241 ovens. | ||
+ | |||
+ | ------------------ | ||
==== 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++, | + | 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++, |
- | Python is inherently class-based, but it's possible to do prototype-based programming with it. In what follows, we will stick exclusively class-based object-orientation. | + | ---[ home ]--- |
==== Ovens and code ==== | ==== Ovens and code ==== | ||
- | So, you get the idea of objects in the physical world. Learning how this relates to computer code is your next step. | + | So, you now get the idea of objects in the physical world. Learning how this relates to computer code is your next step. |
Copyright © 2011-2020 Mithat Konar. All rights reserved. | Copyright © 2011-2020 Mithat Konar. All rights reserved. |
programming_general/object-orientation_fundamentals.txt · Last modified: 2020/11/15 00:03 by mithat