面向对象编程(Object-oriented programming, OOP)

//仅用于记录
C++基于三个基本概念:数据抽象继承动态绑定
数据抽象:用进行数据抽象。
继承:用派生从一个类继承另一个类:派生类继承基类的成员。
动态绑定:使编译器能够在运行时决定是使用基类中定义的函数还是派生类中定义的函数

注:继承和动态绑定容易地定义与其他类相似(similar)但又不相同(different)的新类,能够容易地编写忽略这些相似类型之间区别的程序。

面向对象编程的关键思想是:多态性(polymorphism)。i.e. 许多形态,通过继承而相关联的类型成为多态类型,可以互换地使用派生类型或基类型的“许多形态”。C++中多态性仅用于通过继承而相关联的类型的引用或指针

1.继承
派生类(derived class)能够继承基类base class定义的成员。
基类必须指出希望派生类重定义哪些函数,定义为virtual的函数是基类期待派生类重新定义的,基类希望派生类继承的函数不能定义为虚函数
2.动态绑定
动态绑定dynamic binding:能够通过编写程序使用继承层次中任意类型的对象,无需关心对象的具体类型。使用这些类的程序无需区分函数是在基类还是在派生类中定义的。

//calculate and print price for given number of choices, applying any discounts
void print_total(ostream &os, const Item_base &item, size_t n)
{
		os <<"ISBN:" << item.book()		//calls Item_base::book
			<<"\tnumber sold: "  << n <<"\ttotal price:"
			//virtual call:which version of net_price to call is resolved at run time
			<<item.net_price(n) <<endl;
}

解释:上述函数调用形参Item_base的两个函数book和net_price,打印结果。注意:引用形参Item_base时,可以将对象Item_base或Bulk_item对象传给他;虚函数net_price形参引用时,对net_price的调用将在运行时**确定,调用哪个版本的net_price将依赖于传给print_total的实参。例如:实参为Buck_item对象,将运行Bulk_item中定义的应用折扣的net_price;实参为Item_base对象,则调用Item_base定以的net_price;

总结:动态绑定发生在通过基类的引用(或指针)调用虚函数时。引用(或指针)即可指向基类对象也可以指向派生类对象
用引用(或指针)调用虚函数在运行时确定,被调用的函数是引用所指对象的实际类型所定义的。

Title: R Object-Oriented Programming Author: Kelly Black Length: 190 pages Edition: 1 Language: English Publisher: Packt Publishing Publication Date: 2014-10-23 ISBN-10: 1783986689 ISBN-13: 9781783986682 A practical guide to help you learn and understand the programming techniques necessary to exploit the full power of R About This Book Learn and understand the programming techniques necessary to solve specific problems and speed up development processes for statistical models and applications Explore the fundamentals of building objects and how they program individual aspects of larger data designs Step-by-step guide to understand how OOP can be applied to application and data models within R Who This Book Is For This book is designed for people with some experience in basic programming practices. It is also assumed that they have some basic experience using R and are familiar using the command line in an R environment. Our primary goal is to raise a beginner to a more advanced level to make him/her more comfortable creating programs and extending R to solve common problems. In Detail R is best suited to produce data and visual analytics through customizable scripts and commands, instead of typical statistical tools that provide tick boxes and drop-down menus for users. The book is divided into three parts to help you perform these steps. It starts by providing you with an overview of the basic data types, data structures, and tools available in R that are used to solve common tasks. It then moves on to offer insights and examples on object-oriented programming with R; this includes an introduction to the basic control structures available in R with examples. It also includes details on how to implement S3 and S4 classes. Finally, the book provides three detailed examples that demonstrate how to bring all of these ideas together. Table of Contents Chapter 1. Data Types Chapter 2. Organizing Data Chapter 3. Saving Data and Printing Results Chapter 4. Calculating Probabilities and Random Numbers Chapter 5. Character and String Operations Chapter 6. Converting and Defining Time Variables Chapter 7. Basic Programming Chapter 8. S3 Classes Chapter 9. S4 Classes Chapter 10. Case Study – Course Grades Chapter 11. Case Study – Simulation
Build sophisticated web applications by mastering the art of Object-Oriented Javascript About This Book Learn popular Object-Oriented programming (OOP) principles and design patterns to build robust apps Implement Object-Oriented concepts in a wide range of frontend architectures Capture objects from real-world elements and create object-oriented code that represents them Learn the latest ES6 features and how to test and debug issues with JavaScript code using various modern mechanisms Who This Book Is For JavaScript developers looking to enhance their web developments skills by learning object-oriented programming. What You Will Learn Get acquainted with the basics of JavaScript language constructs along with object-oriented programming and its application. Learn to build scalable server application in JavaScript using Node.js Generate instances in three programming languages: Python, JavaScript, and C# Work with a combination of access modifiers, prefixes, properties, fields, attributes, and local variables to encapsulate and hide data Master DOM manipulation, cross-browser strategies, and ES6 Identify and apply the most common design patterns such as Singleton, Factory, Observer, Model-View-Controller, and Mediator Patterns Design applications using a modular architecture based on SOLID principles In Detail JavaScript is the behavior, the third pillar in today's paradigm that looks at web pages as something that consists of : content (HTML), presentation (CSS), and behavior (JavaScript). Using JavaScript, you can create interactive web pages along with desktop widgets, browser, and application extensions, and other pieces of software. Object-oriented programming, which is popularly known as OOP, is basically based on the concept of objects rather than actions. The first module will help you master JavaScript and build futuristic web applications. You will start by getting acquainted with the language constructs and how to organize code easily. You develop concrete understanding of variable scoping, loops, and best practices on using types and data structures, as well as the coding style and recommended code organization patterns in JavaScript. The book will also teach you how to use arrays and objects as data structures. By the end of the book, you will understand how reactive JavaScript is going to be the new paradigm. The second module is an easy-to-follow course, which includes hands-on examples of solutions to common problems with object-oriented code. It will help to identify objects from real-life scenarios, to protect and hide data with the data encapsulation features of Python, JavaScript, and C#. You will discover the advantage of duck typing in both Python and JavaScript, while you work with interfaces and generics in C#. With a fair understanding of interfaces, multiple inheritance, and composition, you will move on to refactor existing code and to organize your source for easy maintenance and extension. The third module takes you through all the in-depth and exciting futures hidden behind the facade. You should read through this course if you want to be able to take your JavaScript skills to a new level of sophistication. Style and approach This course is a comprehensive guide where each chapter consists of best practices, constructive advice, and few easy-to-follow examples that will build up your skills as you advance through the book. Get object oriented with this course, which takes you on a journey to get acquainted with few useful hands-on tools, features, and ways to enhance your productivity using OOP techniques. It will also act as a reference guide with useful examples on resolving problems with object-oriented code in Python, JavaScript, and C#. Table of Contents Chapter 1: Javascript Primer Chapter 2: Functions, Closures, And Modules Chapter 3: Data Structures And Manipulation Chapter 4: Object-Oriented Javascript Chapter 5: Javascript Patterns Chapter 6: Testing And Debugging Chapter 7: Ecmascript 6 Chapter 8: Dom Manipulation And Events Chapter 9: Server-Side Javascript Chapter 10: Objects Everywhere Chapter 11: Classes And Instances Chapter 12: Encapsulation Of Data Chapter 13: Inheritance And Specialization Chapter 14: Interfaces, Multiple Inheritance, And Composition Chapter 15: Duck Typing And Generics Chapter 16: Organization Of Object-Oriented Code Chapter 17: Taking Full Advantage Of Object-Oriented Programming Chapter 18: Object-Oriented Javascript Chapter 19: Primitive Data Types, Arrays, Loops, And Conditions Chapter 20: Functions Chapter 21: Objects Chapter 22: Prototype Chapter 23: Inheritance Chapter 24: The Browser Environment Chapter 25: Coding And Design Patterns Chapter 26: Reserved Words Chapter 27: Built-In Functions Chapter 28: Built-In Objects Chapter 29: Regular Expressions
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值