<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Virtual Function on Cheat Sheet</title><link>/tags/virtual-function/</link><description>Recent content in Virtual Function on Cheat Sheet</description><generator>Hugo</generator><language>en</language><atom:link href="/tags/virtual-function/index.xml" rel="self" type="application/rss+xml"/><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>