<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>OOP on Cheat Sheet</title><link>/tags/oop/</link><description>Recent content in OOP on Cheat Sheet</description><generator>Hugo</generator><language>en</language><atom:link href="/tags/oop/index.xml" rel="self" type="application/rss+xml"/><item><title>Classes</title><link>/programming/cpp/primer/classes/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/programming/cpp/primer/classes/</guid><description>&lt;h1 id="classes"&gt;Classes&lt;a class="anchor" href="#classes"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Based on &lt;em&gt;C++ Primer, 5th ed.&lt;/em&gt; Chapter 7 (Classes).&lt;/p&gt;
&lt;h2 id="1-member-functions-and-the-implicit-this-pointer"&gt;1. Member Functions and the Implicit &lt;code&gt;this&lt;/code&gt; Pointer&lt;a class="anchor" href="#1-member-functions-and-the-implicit-this-pointer"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Member functions access the object on which they were called through an extra, implicit parameter named &lt;code&gt;this&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;It is illegal for us to define a parameter or variable named &lt;code&gt;this&lt;/code&gt;, because &lt;code&gt;this&lt;/code&gt; is intended to always refer to &amp;ldquo;this&amp;rdquo; object, &lt;code&gt;this&lt;/code&gt; is a &lt;code&gt;const&lt;/code&gt; pointer. (&lt;code&gt;CLASS *const this&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="const-member-functions"&gt;&lt;code&gt;const&lt;/code&gt; Member Functions&lt;a class="anchor" href="#const-member-functions"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;A &lt;strong&gt;&lt;code&gt;const&lt;/code&gt; member function&lt;/strong&gt; (a member function with &lt;code&gt;const&lt;/code&gt; placed after the parameter list &lt;code&gt;()&lt;/code&gt;, e.g., &lt;code&gt;void bar() const&lt;/code&gt;) changes &lt;code&gt;this&lt;/code&gt; to &lt;code&gt;const CLASS *const this&lt;/code&gt; so that the object cannot be modified.&lt;/p&gt;</description></item><item><title>Object-Oriented Programming (OOP)</title><link>/programming/cpp/primer/oop/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/programming/cpp/primer/oop/</guid><description>&lt;h1 id="object-oriented-programming-oop"&gt;Object-Oriented Programming (OOP)&lt;a class="anchor" href="#object-oriented-programming-oop"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Based on &lt;em&gt;C++ Primer, 5th ed.&lt;/em&gt;, Chapter 15: Object-Oriented Programming and Section 19.2.1: &lt;code&gt;dynamic_cast&lt;/code&gt;, this post summarizes the three pillars of OOP, &lt;strong&gt;Upcast / Downcast, Object Slicing, and Polymorphic Containers&lt;/strong&gt;, &lt;strong&gt;Virtual Functions&lt;/strong&gt; (&lt;code&gt;virtual&lt;/code&gt;, &lt;code&gt;override&lt;/code&gt;, &lt;code&gt;final&lt;/code&gt;), &lt;strong&gt;Pure Virtual Functions&lt;/strong&gt; (&lt;code&gt;= 0&lt;/code&gt;) and &lt;strong&gt;Abstract Base Classes&lt;/strong&gt;, and access control under inheritance.&lt;/p&gt;
&lt;h2 id="1-the-three-pillars-of-oop"&gt;1. The Three Pillars of OOP&lt;a class="anchor" href="#1-the-three-pillars-of-oop"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Object-oriented programming is built on three core principles:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Data Abstraction:&lt;/strong&gt; Define classes that separate interface from implementation. — see &lt;a href="../../programming/cpp/primer/classes/"&gt;Classes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Inheritance:&lt;/strong&gt; Define classes that model the relationships among similar types.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dynamic Binding:&lt;/strong&gt; Use objects of derived types while ignoring the details of how they differ.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="2-upcast-vs-downcast-and-static-vs-dynamic-type"&gt;2. Upcast vs. Downcast and Static vs. Dynamic Type&lt;a class="anchor" href="#2-upcast-vs-downcast-and-static-vs-dynamic-type"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Expressions dealing with polymorphic types distinguish between two types:&lt;/p&gt;</description></item></channel></rss>