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
programming_general:object-orientation_fundamentals [2020/09/14 00:58] mithatprogramming_general:object-orientation_fundamentals [2020/11/15 00:03] (current) – [Object-oriented concepts] mithat
Line 1: Line 1:
 ====== Object-Orientation Fundamentals ====== ====== Object-Orientation Fundamentals ======
- 
------------------- 
  
 ===== Why object-orientation? ===== ===== Why object-orientation? =====
Line 10: Line 8:
 OOAD was created to try to solve some of the issues involved in designing and managing large applications. OOAD was created 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 when using procedural/structured programming. With procedural/structured programming thinking, a developer typically thinks in terms of, "What needs to //happen//?" It tends to focus on creating a set of functions or subroutines to do the things that need to get done. Thus, the modularity in procedural programming derives primarily from the "verbs" in the system.
  
-It represents a shift in the way you typically approach a problem using procedural/structured programming thinking. With procedural/structured programming thinking, a developer will typically think in terms of, "What needs to //happen//?" It tends to focus on creating a set of functions or subroutines to do the things that need to get done. The modularity in procedural/structured programming derives primarily from the "verbs" in the system.+In object-oriented thinking, you start with, "What are the components (i.e., objects) that make up the problem?" Once you identify those, you then ask, "How do they behave?" and then, "How do the components interact?" So, the modularity in object-oriented thinking derives primarily from the "nouns" in the system.
  
------------------- +You can //analyze// and //design// your problem using this //object-oriented// perspective and then implement the design in any language. However, 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**.
- +
-In object-oriented thinking, you start with, "What are the components (objects) that make up the problem?" Once you identify those, you then ask, "How do they behave?" and then, "How do the components interact?" The modularity in object-oriented thinking derives primarily from the "nouns" in the system. +
- +
------------------- +
- +
-While it is possible to analyze and design systems (i.e., applications) using this approach and 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**.+
  
 So, OOAD facilitates a higher level of modular thinking. And, especially with an object-oriented language, it allows for very effective project management of large applications. So, OOAD facilitates a higher level of modular thinking. And, especially with an object-oriented language, it allows for very effective project management of large applications.
- 
------------------- 
  
 ===== Object-oriented concepts ===== ===== Object-oriented concepts =====
  
-The concept of an object in computing comes directly from the concept of an "object" in the real world. The concepts critical to understanding object-orientation in programming are:+The concept of an object in computing comes directly from the concept of an "object" in the real world. The concepts central to understanding object-orientation in programming are:
  
   * state   * state
Line 36: Line 26:
  
 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 49: Line 37:
  
 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 62: Line 48:
  
 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 ====
Line 71: Line 55:
  
 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.
- 
------------------- 
  
 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.
  
 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 86: Line 66:
  
 To put it another way, an object is a program entity that encapsulates state and behavior for some meaningful abstraction. It does this by using attributes and operations involving those attributes. To put it another way, an object is a program entity that encapsulates state and behavior for some meaningful abstraction. It does this by using attributes and operations involving those attributes.
- 
------------------- 
  
 ==== Class-based object-orientation ==== ==== Class-based object-orientation ====
Line 98: Line 76:
  
 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 ====
Line 105: Line 81:
 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-orientation. JavaScript 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. 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-orientation. JavaScript 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.
  
----[ home ]--- 
  
 ==== Ovens and code ==== ==== Ovens and code ====
programming_general/object-orientation_fundamentals.1600045082.txt.gz · Last modified: 2020/09/14 00:58 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki