100% found this document useful (4 votes)
36 views

[Ebooks PDF] download Simple and Efficient Programming with C# : Skills to Build Applications with Visual Studio and .NET 2nd Edition Vaskaran Sarcar full chapters

Sarcar

Uploaded by

boyenskarger
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (4 votes)
36 views

[Ebooks PDF] download Simple and Efficient Programming with C# : Skills to Build Applications with Visual Studio and .NET 2nd Edition Vaskaran Sarcar full chapters

Sarcar

Uploaded by

boyenskarger
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 75

Download Full Version ebookmass - Visit ebookmass.

com

Simple and Efficient Programming with C# : Skills


to Build Applications with Visual Studio and .NET
2nd Edition Vaskaran Sarcar

https://ebookmass.com/product/simple-and-efficient-
programming-with-c-skills-to-build-applications-with-visual-
studio-and-net-2nd-edition-vaskaran-sarcar-2/

OR CLICK HERE

DOWLOAD NOW

Discover More Ebook - Explore Now at ebookmass.com


Instant digital products (PDF, ePub, MOBI) ready for you
Download now and discover formats that fit your needs...

Simple and Efficient Programming with C# : Skills to Build


Applications with Visual Studio and .NET 2nd Edition
Vaskaran Sarcar
https://ebookmass.com/product/simple-and-efficient-programming-with-c-
skills-to-build-applications-with-visual-studio-and-net-2nd-edition-
vaskaran-sarcar-2/
ebookmass.com

Pro Cryptography and Cryptanalysis with C++23: Creating


and Programming Advanced Algorithms 2nd Edition Marius
Iulian Mihailescu
https://ebookmass.com/product/pro-cryptography-and-cryptanalysis-
with-c23-creating-and-programming-advanced-algorithms-2nd-edition-
marius-iulian-mihailescu-2/
ebookmass.com

Pro Cryptography and Cryptanalysis with C++23: Creating


and Programming Advanced Algorithms, 2nd Edition Marius
Iulian Mihailescu
https://ebookmass.com/product/pro-cryptography-and-cryptanalysis-
with-c23-creating-and-programming-advanced-algorithms-2nd-edition-
marius-iulian-mihailescu/
ebookmass.com

Microeconomia. Quarta edizione David A. Besanko

https://ebookmass.com/product/microeconomia-quarta-edizione-david-a-
besanko/

ebookmass.com
The Precision Farming Revolution: Global Drivers of Local
Agricultural Methods 1st ed. 2020 Edition James E.
Addicott
https://ebookmass.com/product/the-precision-farming-revolution-global-
drivers-of-local-agricultural-methods-1st-ed-2020-edition-james-e-
addicott/
ebookmass.com

Neglected Tropical Diseases and Phytochemicals in Drug


Discovery Chukwuebuka Egbuna & Muhammad Akram & Jonathan
Chinenye Ifemeje
https://ebookmass.com/product/neglected-tropical-diseases-and-
phytochemicals-in-drug-discovery-chukwuebuka-egbuna-muhammad-akram-
jonathan-chinenye-ifemeje/
ebookmass.com

Mathematical Rigour and Informal Proof 1st Edition Fenner


Stanley Tanswell

https://ebookmass.com/product/mathematical-rigour-and-informal-
proof-1st-edition-fenner-stanley-tanswell/

ebookmass.com

Male and Sperm Factors that Maximize IVF Success 1st


Edition John Aitken

https://ebookmass.com/product/male-and-sperm-factors-that-maximize-
ivf-success-1st-edition-john-aitken/

ebookmass.com

(eTextbook PDF) for Doing Ethics: Moral Reasoning, Theory,


and Contemporary Issues 5th Edition

https://ebookmass.com/product/etextbook-pdf-for-doing-ethics-moral-
reasoning-theory-and-contemporary-issues-5th-edition/

ebookmass.com
Navigating Urban Soundscapes: Dublin and Los Angeles in
Fiction Annika Eisenberg

https://ebookmass.com/product/navigating-urban-soundscapes-dublin-and-
los-angeles-in-fiction-annika-eisenberg/

ebookmass.com
Vaskaran Sarcar

Simple and Efficient Programming with


C#
Skills to Build Applications with Visual Studio and
.NET
2nd ed.
Vaskaran Sarcar
Kolkata, West Bengal, India

ISBN 978-1-4842-8736-1 e-ISBN 978-1-4842-8737-8


https://doi.org/10.1007/978-1-4842-8737-8

© Vaskaran Sarcar 2021, 2023

This work is subject to copyright. All rights are solely and exclusively
licensed by the Publisher, whether the whole or part of the material is
concerned, specifically the rights of translation, reprinting, reuse of
illustrations, recitation, broadcasting, reproduction on microfilms or in
any other physical way, and transmission or information storage and
retrieval, electronic adaptation, computer software, or by similar or
dissimilar methodology now known or hereafter developed.

The use of general descriptive names, registered names, trademarks,


service marks, etc. in this publication does not imply, even in the
absence of a specific statement, that such names are exempt from the
relevant protective laws and regulations and therefore free for general
use.

The publisher, the authors, and the editors are safe to assume that the
advice and information in this book are believed to be true and accurate
at the date of publication. Neither the publisher nor the authors or the
editors give a warranty, expressed or implied, with respect to the
material contained herein or for any errors or omissions that may have
been made. The publisher remains neutral with regard to jurisdictional
claims in published maps and institutional affiliations.

This Apress imprint is published by the registered company APress


Media, LLC, part of Springer Nature.
The registered company address is: 1 New York Plaza, New York, NY
10004, U.S.A.
I dedicate this book to the programming lovers of C#.
Introduction
It is my absolute pleasure to write the second edition of Simple and
Efficient Programming with C#: Skills to Build Applications with Visual
Studio and .NET. You can surely guess that I got this opportunity
because you liked the previous edition of the book and shared your
feedback with us. So, once again I’m excited to join you and help you to
learn more. This time I present a further simplified, better organized,
and more content-rich edition to you.
Let me remind you of the key goals of this book. I wrote about them
in the first edition as well. C# is an object-oriented programming (OOP)
language. You may already know C# keywords or even some interesting
features. You may also know how to write simple programs in C#. You
can learn these things from an introductory book or an online tutorial.
These are useful things to know, but they are not sufficient to
understand an enterprise codebase. This is why a novice programmer
often finds it difficult to understand an expert’s code. They may wonder
why an experienced programmer wrote the program in a particular
way. It may appear to the novice that the expert could have used an
easier approach to solve the problem. But there are reasons why an
experienced programmer might follow a different approach. The word
experienced indicates that these programmers have more experience in
programming and know the pros and cons of different approaches.
They know how the C# features can be used in the best possible way to
develop an application. So, the applications they make are usually
powerful. What do I mean by a powerful application? For me, a
powerful application is robust, extensible, and easily maintainable, but
simple to use. This book is an introductory guide for developing such
applications. This was the core aim of this book.
To write better-quality programs, senior programmers follow
experts’ footprints. They learn from the collective wisdom and recorded
experience of the past. So, instead of attempting an entirely new
solution, you should first consider this knowledge base, which will help
you produce better-quality code. It is always better if you know about
why you should or shouldn’t follow any specific guideline.
Malcolm Gladwell, in his book Outliers (Little, Brown and Company),
discussed the 10,000-hour rule. This rule says that the key to achieving
world-class expertise in any skill is, to a large extent, a matter of
practicing the correct way, for a total of around 10,000 hours. I
acknowledge that it is impossible to consider all experiences before you
write a program. Also, sometimes it is OK to bend the rules if the return
on investment (ROI) is nice. So, keep in mind the Pareto principle, or
the 80-20 rule. This rule simply states that 80 percent of outcomes
come from 20 percent of all causes. This is useful in programming too.
When you identify the most essential characteristics of top-quality
programs and use them in your applications, you also qualify yourself
as an experienced programmer, and your application will be robust,
flexible, and maintainable. In this book, I share with you these
important principles using some case studies, which will help you write
better programs. Some of these principles you may know already, but
when you see them in action and compare these case studies, you’ll
understand their importance.
So, what is new in this second edition? Well, the first thing I want
to tell you is that this edition maintains the same goals that were
mentioned in the first edition. Second, you can easily guess that it is a
further simplified, enlarged, and polished version. This time you see the
use of top-level statements throughout the book. You may know that
top-level statements have been supported since C# 9.0. In addition, the
.NET 6+ project template for C# console apps uses top-level statements.
At the time of this writing, C# 11 is not released, but you can test the
preview features. I have taken this opportunity to use some of them,
particularly raw-string literals. I talk about static abstract interface
members too. I used many preview features in my other book, Test Your
Skills in C# Programming. But for this book, not all of them are required.
Additionally, this is an expanded edition. Two new chapters in Part
IV, Chapter 10 and Chapter 11, talk about handling errors in a better
way. Particularly, you’ll see a discussion of organizing exceptions and
handling null values with different case studies.
How Is the Book Organized?
The book has five major parts, which are as follows:
The first three chapters form Part I, in which there is a detailed
discussion of polymorphism and the use of abstract classes and
interfaces. Here, code comments will be examined, and you will learn
when to use them effectively. These are the fundamental building
blocks for the rest of the book.
In the world of programming, there is no shortage of programming
principles and design guidelines. Each of these suggestions has its
own benefits. To become a professional programmer, you do not need
to learn everything at the same time. In Part II, I discuss six design
principles, which include the SOLID principles and the DRY principle.
These are the foundation of well-known design patterns.
The best way to learn is by doing and analyzing case studies. So, in
Part III of the book, you will see interesting applications that use
some well-known patterns. This part gives you hints about how a
professional coder develops an enterprise application.
Handling errors is an unavoidable part of programming. Particularly,
runtime exceptions are dangerous, and often they appear in the form
of NullReferenceException in C#. Part IV focuses on them,
discusses different case studies with easy-to-understand examples,
and provides useful suggestions about possible improvements.
There is no end to learning. So, Part V includes some interesting
topics such as how to prevent memory leaks, how to choose between
a static method and an instance method, and some common terms
from software development that are not discussed in detail in this
book. A quick overview of these topics will help your future learnings
and experiments.
You can download all the source codes for the book from the
publisher’s website. I have a plan to maintain the “errata,” and, if
required, I can also make some updates/announcements there. So, I
suggest you visit those pages to receive any important corrections or
updates.

Prerequisite Knowledge
This book is intended for those who are familiar with the common
language constructs of C# and have a basic understanding of pure
object-oriented concepts such as polymorphism, inheritance,
abstraction, encapsulation, and, most importantly, how to compile or
run a C# application in Visual Studio. This book does not invest time in
easily available topics, such as how to install Visual Studio on your
system, how to write a “Hello World” program in C#, how you can use
an if-else statement or a while loop, etc. This book is written using
the most basic features of C# so that for most of the programs herein
you do not need to be familiar with advanced topics in C#. The
examples are simple, and I believe that they are written in such a way
that even if you are familiar with another popular language such as
Java, C++, and so on, you can still easily grasp the concepts in this book.
Who Is This Book For?
In short, you can pick up this book if the answer is “yes” to the
following questions:
Are you familiar with basic constructs in C# and object-oriented
concepts such as polymorphism, inheritance, abstraction, and
encapsulation?
Do you know how to set up your coding environment?
Have you completed at least one introductory course on C# and now
are interested in writing better programs?
Are you also interested to know how a professional programmer
designs their applications?
You probably shouldn’t pick this book if the answer is yes to any of
the following questions:
Are you absolutely new to C#?
Are you looking for advanced concepts in C#, excluding the topics
mentioned previously?
Are you interested in exploring a book where the focus is not on
standard design principles?
Do you not like Windows, Visual Studio, and/or .NET and want to
learn and use C# without them?

Guidelines for Using This Book


To use this book more effectively, consider the following:
This book works best if you’ve gone through an introductory course
on C# and are familiar with the common terms, such as
polymorphism, and have heard about abstract classes and interfaces.
If this is not the case, please read about these topics before you start
reading this book.
I suggest you go through the chapters sequentially. This is because
some fundamental design techniques may have been discussed in a
previous chapter, and I have not repeated those techniques in later
chapters.
I started this book using Microsoft Visual Studio Community 2022
in a Windows 10 environment. This community edition is free of
charge. When I started the book, I started with the latest versions of
C# that were available at that time. You can easily guess that version
updates kept coming, so I kept updating my code repository. When I
finished my first draft, I had the most recent version of Visual Studio
Community 2022 (version 17.3.3). Almost in every case, my target
framework was .NET 7.0, which supports C# 11.
In this context, it is useful to know that nowadays the C# language
version is automatically selected based on your project’s target
framework(s), so you can always get the highest compatible version
by default.
For example, C# 11 is for .NET 7 and later versions. Similarly, C# 10 is
supported only on .NET 6 and newer versions. C# 9 is supported only
on .NET 5 and newer versions. C# 8.0 is supported only on .NET Core
3.x and newer versions. If you are interested in the C# language
versioning, you can go to this link:
https://docs.microsoft.com/en-
us/dotnet/csharp/language-reference/configure-
language-version.
The fact is that these version updates will come continuously, but I
strongly believe that these version details should not matter much to
you because I have used the fundamental constructs of C#. So, the
code in this book should execute smoothly in the upcoming versions
of C#/Visual Studio as well. Though I also believe that the results
should not vary in other environments, you know the nature of
software—it is naughty. So, I recommend that if you want to see the
exact same output, you mimic the same environment.
If you do not use the Windows operating system, you can use Visual
Studio Code, which is also a source-code editor developed by
Microsoft to support Windows, Linux, or Mac operating systems. This
multiplatform IDE is also free.
You can download and install the Visual Studio IDE from
https://visualstudio.microsoft.com/downloads/. You
will the screen shown in Figure I-1.
Note At the time of writing, this information is correct. But the
link and policies may change in the future.

I have also installed the class designer component in Visual Studio


2022 to draw class diagrams for my programs. They’ll help you
understand the code better.

Figure I-1 Download link for Visual Studio 2022 and Visual Studio Code

Conventions Used in This Book


All the output and code of the book follow the same font and structure.
To draw your attention to some places, I have made them bold. For
example, consider the following code fragment and the lines in bold
(taken from Chapter 4 when I discuss the LSP):

// The previous codes are skipped

// Instantiating two registered users


RegisteredUser robin = new("Robin");
RegisteredUser jack = new("Jack");
helper.AddUser(robin);
helper.AddUser(jack);

GuestUser guestUser1 = new();


helper.AddUser(guestUser1);

// Processing the payments using


// the helper class.
// You can see the problem now.
helper.ShowPreviousPayments();
helper.ProcessNewPayments();

// The remaining codes are skipped

Final Words
You are an intelligent person. You have chosen a subject that can assist
you throughout your career. As you learn about these concepts, I
suggest you write your own code; only then will you master this area.
There is no shortcut to true learning. In a similar context, can you
remember Euclid’s (the ancient Greek mathematician who is often
considered the father of geometry) reply to the ruler? If not, let me
remind you of his reply: “There is no royal road to geometry.” Similarly,
in programming, there is no shortcut. So, study and code; understand a
new concept and code again. Do not give up when you face challenges.
They are the indicators that you are growing better.
I believe that this book is designed for you in such a way that upon
its completion, you will develop an adequate knowledge of the topic,
and, most importantly, you’ll know how to go further. Lastly, I hope that
this book can provide help to you and that you will value the effort.
Any source code or other supplementary material referenced by the
author in this book is available to readers on GitHub
(https://github.com/Apress). For more detailed information, please
visit www.apress.com/source-code.
Table of Contents
Part I: Fundamentals
Chapter 1:​Flexible Code Using Polymorphism
Recap of Polymorphism
Initial Program
Demonstration 1
Output
Analysis
Better Program
Demonstration 2
Analysis
Useful Notes
Summary
Chapter 2:​Abstract Class or Interface?​
Recap of Abstract Classes and Interfaces
Initial Program
Demonstration 1
Better Program
Demonstration 2
Output
Analysis
Summary
Chapter 3:​Wise Use of Code Comments
Recap of Code Comments
Initial Program
Demonstration 1
Output
Analysis
Better Program
Demonstration 2
Analysis
Use the Power of C#
Demonstration 3
Analysis
Summary
Part II: Important Principles
Chapter 4:​Know SOLID Principles
Single Responsibility Principle
Initial Program
Better Program
Open/​Closed Principle
Initial Program
Better Program
Liskov Substitution Principle
Initial Program
Better Program
Analysis
Interface Segregation Principle
Initial Program
Better Program
Dependency Inversion Principle
Initial Program
Better Program
Summary
Chapter 5:​Use the DRY Principle
Reasons for DRY
Initial Program
Demonstration 1
Output
Analysis
Better Program
Demonstration 2
Output
Analysis
Further Improvement
Demonstration 3
Output
Demonstration 4
Output
Summary
Part III: Make Efficient Applications
Chapter 6:​Separate Changeable Code Using Factories
The Problem Statement
Initial Program
Demonstration 1
Output
Analysis
Better Program
Demonstration 2
Output
Analysis
A New Requirement
Demonstration 3
Output
Analysis
Demonstration 4
Output
Summary
Chapter 7:​Add Features Using Wrappers
The Problem Statement
Initial Program (Using Subclassing)
Demonstration 1
Better Program (Using Object Composition)
Class Diagram
Demonstration 2
Output
Analysis
Summary
Chapter 8:​Make Efficient Templates Using Hooks
The Problem Statement
Initial Program
Class Diagram
Demonstration 1
Output
Analysis
Enhanced Requirement
Demonstration 2
Output
Summary
Chapter 9:​Simplify Complex Systems Using Facades
The Problem Statement
Initial Program
Demonstration 1
Output
Analysis
Better Program
Class Diagram
Demonstration 2
Output
Analysis
Summary
Part IV: Handling Surprises in a Better Way
Chapter 10:​Organizing Exceptions
Recap of Exceptions
Case 1:​Handling Different Exceptions in the Same Way
Initial Program
Better Program
Case 2:​Handling the Same Exception in Different Ways
Initial Program
Better Program
Summary
Chapter 11:​Special Attention to the Null Values
Initial Program
Demonstration 1
Output
Analysis
Better Programs
Demonstration 2
Output
Analysis
Demonstration 3
Analysis
Summary
Part V: The Road Ahead
Chapter 12:​Memory Management
Overview
Stack Memory vs.​Heap Memory
Q&​A Session
The Garbage Collector in Action
Different Phases of Garbage Collection
Different Cases of Invoking the Garbage Collector
Demonstration 1
Output
Analysis
Q&​A Session
Disposing of an Object
Finalize vs.​Dispose
Demonstration 2
Output
Analysis
Q&​A Session
Summary
Chapter 13:​Analyzing Memory Leaks
Managed vs.​Unmanaged Memory Leaks
Memory Leak Analysis
Demonstration
Snapshots from Diagnostic Tools
Summary
Chapter 14:​More Tips
Learn Design Patterns
Brief History of Design Patterns
The Good News
Q&​A Session
Avoid Anti-patterns
Brief History of Anti-patterns
Examples of Anti-patterns
Q&​A Session
Final Suggestions
Decide Between a Static Method and an Instance Method
Know the Common Terminology
Accept Failures!
Q&​A Session
Summary
Appendix A:​Winning Notes
Appendix B:​Resources
Index
About the Author
Vaskaran Sarcar
obtained his master’s degree in software
engineering from Jadavpur University,
Kolkata (India), and his MCA from
Vidyasagar University, Midnapore
(India). He was a National Gate Scholar
(2007–2009) and has more than 12
years of experience in education and the
IT industry. Vaskaran devoted his early
career (2005–2007) to the teaching
profession at various engineering
colleges, and later he joined HP India
PPS R&D Hub Bangalore. He worked
there until August 2019. At the time of
his retirement from HP, he was a senior
software engineer and team lead. To
follow his dream and passion, Vaskaran
is now an independent full-time author. Other Apress books by
Vaskaran include:
Test your Skills in C# Programming (Apress, 2022)
Java Design Patterns, Third Edition (Apress, 2022)
Simple and Efficient Programming in C# (Apress, 2021)
Design Patterns in C#, Second Edition (Apress, 2020)
Getting Started with Advanced C# (Apress, 2020)
Interactive Object-Oriented Programming in Java, Second Edition
(Apress, 2019)
Java Design Patterns, Second Edition (Apress, 2019)
Design Patterns in C# (Apress, 2018)
Interactive C# (Apress, 2017)
Interactive Object-Oriented Programming in Java (Apress, 2016)
Java Design Patterns (Apress, 2016)
The following are other books he’s written:
Python Bookcamp (Amazon, 2021)
Operating System: Computer Science Interview Series (Createspace,
2014)
About the Technical Reviewers
Shekhar Kumar Maravi
is a lead engineer in design and
development whose main interests are
programming languages, algorithms, and
data structures. He obtained his master’s
degree in computer science and
engineering from the Indian Institute of
Technology – Bombay. After graduation,
he joined Hewlett-Packard’s R&D Hub in
India to work on printer firmware.
Currently he is a technical lead engineer
for automated pathology lab diagnostic
devices at Siemens Healthcare R&D
division. He can be reached by email at
shekhar.maravi@gmail.com or via
LinkedIn at www.linkedin.com/in/shekharmaravi.

Carsten Thomsen
is a back-end developer primarily but
works with smaller front-end bits as
well. He has authored and reviewed a
number of books and created numerous
Microsoft Learning courses, all to do
with software development. He works as
a freelancer/contractor in various
countries in Europe, using Azure, Visual
Studio, Azure DevOps, and GitHub. He
also enjoys working with architecture,
research, analysis, development, testing,
and bug fixing.
Part I
Funda
mentals
Part I consists of three chapters, in which we will discuss the following
questions:
How can we use the power of polymorphism, and why is it
beneficial?
How can we combine an abstract class and interfaces to make an
efficient application?
How can we use meaningful code comments and avoid unnecessary
comments in a program?
Almost every C# application uses comments, the concept of
polymorphism, and abstract classes and interfaces. When we
implement these techniques in a better way, the program is better. I
consider them the fundamental techniques for an efficient application.
© The Author(s), under exclusive license to APress Media, LLC, part of Springer
Nature 2023
V. Sarcar, Simple and Efficient Programming with C#
https://doi.org/10.1007/978-1-4842-8737-8_1

1. Flexible Code Using Polymorphism


Vaskaran Sarcar1

(1) Kolkata, West Bengal, India

Ask a developer the following question: “What are the fundamental


characteristics of object-oriented programming (OOP)?” You will hear
an immediate reply saying that classes (and objects), inheritance,
abstraction, encapsulation, and polymorphism are the most important
characteristics of OOP. In addition, when you analyze OOP-based
enterprise code, you’ll find different forms of polymorphism. But the
truth is that a novice programmer rarely uses the power of
polymorphism. Why? It is said that object-oriented programmers pass
through three important stages. In the first stage, they become familiar
with non-object-oriented constructs. In this stage, they use decision
statements, looping constructs, etc. In the second stage, they start
creating classes and objects and use the inheritance mechanism. Finally,
in the third stage, they use polymorphism to achieve late binding and
make their programs flexible. But writing the polymorphic is not always
easy. Honestly, it is a little bit tough compared to the other features of
OOP. Using some simple but powerful code examples, this chapter will
make this concept easy for you to understand.

Recap of Polymorphism
Polymorphism simply means there is one name with many forms. In the
real world, it is a common phenomenon. Consider the behavior of your
pet dog: when it sees an unknown person, it starts barking. But when it
sees you, it makes different noises and behaves differently. In both
cases, this dog sees with its eyes, but based on the observation, the dog
behaves differently.
You can relate this concept to other areas as well. For example,
consider the customer support departments in different organizations.
They each provide support to the customers in their own way. Similarly,
each of the search engine providers such as Google, Yahoo, or Microsoft
Bing searches the Internet following its own algorithm.
OOP likes to mimic real-world scenarios, and conceptually, the
polymorphic code works in the same way. In C#, a class can have
methods (or properties). Optionally, you can provide implementations
for them. C# also allows the derived classes to override those
implementations as per their needs. As a result, these related types can
have methods with the same name, but they can show different
behaviors. This is the key concept to understand before you deal with
the polymorphic code.

Initial Program
The importance of a feature is often realized in the absence of it. So, I
start with a program that does not use the concept of polymorphism.
This program compiles and runs successfully. Here you have three
different types of animals—tigers, dogs, and monkeys. Each of
them can produce a different sound. So, I made classes with their
corresponding names, and in each class, you see a Sound() method.
Check whether you can improve this program.

Demonstration 1
Here is the complete demonstration:

Console.WriteLine("***Sounds of the different


animals.***");
Tiger tiger = new();
tiger.Sound();
Dog dog = new();
dog.Sound();
Monkey monkey = new();
monkey.Sound();
Console.ReadKey();
class Tiger
{
public void Sound()
{
Console.WriteLine("Tigers roar.");
}
}
class Dog
{
public void Sound()
{
Console.WriteLine("Dogs bark.");
}
}
class Monkey
{
public void Sound()
{
Console.WriteLine("Monkeys whoop.");
}
}

Output
Here is the output:

***Sounds of the different animals.***


Tigers roar.
Dogs bark.
Monkeys whoop.

Analysis
I have used the simplified new expressions here. For example, the line
Tiger tiger = new(); is the simplified version of Tiger tiger
= new Tiger(); Starting with C# 9.0, you can use this form. It says
that during the constructor invocation if the target type of an
expression is known, you can omit the type name.
When you use Tiger tiger = new Tiger();, the tiger is a
reference to an object that is based on the Tiger class. This reference
refers to the object, but it does not contain the object data itself. Even
Tiger tiger; is a valid line of code that creates an object reference
without creating the actual object.
Understand that when you use Tiger tiger = new
Tiger();, we say that you are programming to an implementation.
Notice that in this case the reference and object both are of the same
type. You can improve this program using the concept of
polymorphism. In the upcoming implementation, I show you such an
example. I use an interface in this example. Before I show you the
example, let me remind you of a few important points:
I could achieve the same effect using an abstract class. When you use
an abstract class or an interface, the first thing that comes to mind is
inheritance. How do you know whether you are correctly using
inheritance? The simple answer is that you do an IS-A test. For
example, a rectangle IS-A shape, but the reverse is not necessarily
true. Take another example: a monkey IS-An animal, but not all
animals are monkeys. Notice that the IS-A test is unidirectional.
In programming, if you inherit class B from class A, you say that B is
the subclass and A is the parent class or base class. But most
importantly, you can say B is a type of A. So, if you derive a Tiger
class or a Dog class from a base class called Animal (or an interface
say IAnimal), you can say that Dog IS-An Animal (or IAnimal) or
Tiger IS-An Animal (or IAnimal). Similarly, a rectangle IS-A
special type of shape. A square IS-A special type of rectangle. So, a
square IS-A shape too.
If you have an inheritance tree, this IS-A test can be applied
anywhere in the tree.
Let us assume that I represent rectangles and shapes using the
Rectangle and Shape classes, respectively. Now when I say
Rectangle IS-A Shape, programmatically I tell that a Rectangle
instance can invoke the methods that a Shape instance can invoke.
But, if needed, a Rectangle class can include some specific
methods that are absent in the Shape class. To invoke these specific
methods, you need to use a Rectangle instance only; since the
Shape class does not include those methods, the Shape instances
cannot call them.
In C#, a parent (or base) class reference can refer to a subclass
object. Since each tiger, dog, or monkey is an animal, you can
introduce a parent type and inherit all these concrete classes from it. I
told you that I am going to use a C# interface now. Following the C#
naming convention, let’s name the supertype as IAnimal.
Here is a code fragment that shows the IAnimal interface. It also
gives you an idea of how to override its Sound() method in the Tiger
class. The Monkey and Dog class can do the same thing.

interface IAnimal
{
void Sound();
}
class Tiger : IAnimal
{
public void Sound()
{
Console.WriteLine("Tigers roar.");
}
}

Programming to a supertype gives you more flexibility. It allows you


to use a reference variable polymorphically. The following code
segment demonstrates such a usage:

IAnimal animal = new Tiger();


animal.Sound();
animal = new Dog();
animal.Sound();
// The remaining code skipped

Better Program
Now I rewrite this program which produces the same output. Let’s take
a look at the following demonstration.

Demonstration 2
Here is demonstration 2. It is a modified version of demonstration 1.

Console.WriteLine("***Sounds of the different


animals.***");

IAnimal animal = new Tiger();


animal.Sound();
animal = new Dog();
animal.Sound();
animal = new Monkey();
animal.Sound();

interface IAnimal
{
void Sound();
}
class Tiger : IAnimal
{
public void Sound()
{
Console.WriteLine("Tigers roar.");
}
}
class Dog : IAnimal
{
public void Sound()
{
Console.WriteLine("Dogs bark.");
}
}
class Monkey : IAnimal
{
public void Sound()
{
Console.WriteLine("Monkeys whoop.");
}
}

Analysis
Have you noticed the difference? This time I used the superclass
reference animal to refer to different derived class objects.
Following this approach, not only do you type less, but you also use
a program that is more flexible and easier to maintain. If needed, now
you can iterate over a list too. For example, you can replace the
following code segment inside Main():

IAnimal animal = new Tiger();


animal.Sound();
animal = new Dog();
animal.Sound();
animal = new Monkey();
animal.Sound();

with the following code:

List<IAnimal> animals = new List<IAnimal>


{
new Tiger(),
new Dog(),
new Monkey()
};

foreach (IAnimal animal in animals)


animal.Sound();

If you run the program again with these changes, you see the same
output.
Notice that in demonstration 1, when a client reads the line
dog.Sound(), they can assume that the Sound() method from the
Dog class will be invoked.
But in demonstration 2, when the client reads the line
animal.Sound(), it is not obvious which subtype of IAnimal will
invoke the Sound(). Why is this important? As a programmer, you do
not provide every possible detail to your clients.
This discussion is not over yet. Here I have used one of the simplest
forms of polymorphism. In this case, a question may come to mind: we
know a supertype reference can refer to a subtype object in C#. So,
when I use the following lines:

IAnimal animal = new Tiger();


animal.Sound();

you can surely predict that the Sound() method of Tiger class
will be used. So, it appears that you know the output in advance and
you doubt the concept of polymorphism. If this is the case, let us further
dig into this.
Let us assume that you create a subtype based on some runtime
random number generator (or user input). In this case, you cannot
predict the output in advance. For example, see the following lines of
code:

IAnimal animal = AnimalProducer.GetAnimal();


animal.Sound();

What is the difference? Anyone who sees this code segment can
assume that GetAnimal() of the AnimalProducer class returns an
animal that can make some sound. How can you achieve this? It is
pretty simple: let me rewrite the program. Notice the changes in bold:

Console.WriteLine("***Sounds of the different


animals.***");
IAnimal animal = AnimalProducer.GetAnimal();
animal.Sound();
animal = AnimalProducer.GetAnimal();
animal.Sound();
animal = AnimalProducer.GetAnimal();
animal.Sound();
interface IAnimal
{
void Sound();
}
class Tiger : IAnimal
{
public void Sound()
{
Console.WriteLine("Tigers roar.");
}
}
class Dog : IAnimal
{
public void Sound()
{
Console.WriteLine("Dogs bark.");
}
}
class Monkey : IAnimal
{
public void Sound()
{
Console.WriteLine("Monkeys whoop.");
}
}

class AnimalProducer
{
internal static IAnimal GetAnimal()
{
IAnimal animal;
Random random = new Random();
// Get a number between 0 and 3(exclusive)
int temp = random.Next(0, 3);

if (temp == 0)
{
animal = new Tiger();
}
else if (temp == 1)
{
animal = new Dog();
}
else
{
animal = new Monkey();
}
return animal;
}
}
Run this application now and notice the output. Here is the sample
output that I got on the various runs:

First Run:

***Sounds of the different animals.***


Monkeys whoop.
Dogs bark.
Monkeys whoop.

Second Run:

***Sounds of the different animals.***


Dogs bark.
Dogs bark.
Tigers roar.

Third Run:

***Sounds of the different animals.***


Tigers roar.
Monkeys whoop.
Dogs bark.
It is now clear that no one can predict the output of this program in
advance. You can see the effective use of polymorphism in this example.

POINTS TO REMEMBER
If you like to shorten this code, instead of using the if-else chain,
you can use the switch expression as follows:

animal =
temp switch
{
0 => new Tiger(),
1 => new Dog(),
_ => new Monkey()
};

One more point: you can use a simplified new expression again.
For example, the line Random random = new Random(); can
be shortened if you use Random random = new();. When you
download the source code from the Apress website, refer to the
folder Demo3_Polymorphism inside Chapter1 to see the
complete program.

Now I’ll show you some code that helps you understand and use
polymorphic code in an alternative way. You can replace
animal.Sound(); with the following code:

AnimalProducer.MakeSound(animal);

MakeSound() is defined inside the AnimalProducer class as


follows:

internal static void MakeSound(IAnimal animal)


{
animal.Sound();
}
Why am I showing this to you? Following this approach, you can
pass a supertype reference to this method to invoke the appropriate
subtype method. This also gives you flexibility and helps you write
better, more readable code. Here is an alternative version of the
program that we have just discussed:

Console.WriteLine("***Sounds of the different


animals.***");
IAnimal animal = AnimalProducer.GetAnimal();
AnimalProducer.MakeSound(animal);
animal = AnimalProducer.GetAnimal();
AnimalProducer.MakeSound(animal);
animal = AnimalProducer.GetAnimal();
AnimalProducer.MakeSound(animal);

interface IAnimal
{
void Sound();
}
class Tiger : IAnimal
{
public void Sound()
{
Console.WriteLine("Tigers roar.");
}
}
class Dog : IAnimal
{
public void Sound()
{
Console.WriteLine("Dogs bark.");
}
}
class Monkey : IAnimal
{
public void Sound()
{
Random documents with unrelated
content Scribd suggests to you:
love to ye, can't change your nature sudden-like. Ye'll fit in
by and by. Don't I mean that when I says sometimes the
Lord 'ud put me in a palace, if 'twas good for me, but I
wouldn't be over happy in it. Sure I haven't got palace
tastes, nor palace ways,—an' little Lettie's in a grand house,
and she haven't got grand house tastes, nor ways neither,
eh?"

"She will learn all that by and by," said Leveson,


stroking her head. "But I think Lettie's difficulty makes
another picture for you if you want one. Do you see it?"

"Sure an' I do, sir. Why, if a man was took right to


heaven, without learnin' to have heaven's tastes, he
wouldn't be a bit happier nor fitter nor better off than old
Job Kippis in the Queen's palace. What'd he care for the
singin' praises to God, and livin' for His service, and lookin'
into His glory, an' doin' His will? It's dull work he'd find it all,
—lest he had the love of God in his heart, sir, an' his sinful
nature washed an' fitted for heaven. Ain't it that you
meant?"

"Just that," said Leveson. "But very few men realize it,
or know that to be taken to heaven, unfitted for heaven's
work and glory, would be no boon. As well take a blind man
to see beautiful scenery, or a deaf man to hear sweet
music, as talk of a man who is deaf and blind to God's love
and beauty, finding any happiness in heaven. But you—"
Leveson went on after a moment's break,—"you, I trust, are
no longer deaf and blind. Heaven will not be to you what
our home, with all our efforts, must for a time be to little
Lettie."

"Aye, sir, an' I don't think that the river Jordan's far
distant neither," said Job. "No, I'm noways loath to go,—
save for leavin' little Ailie tossin' about with no one to take
pity on her. But I think ye'll be a friend to the poor little
lamb, sir."

CHAPTER XXV.
THROUGH THE WATERS.

LETTIE settled down into her new home, slowly learning


to love those around her, and gradually becoming
accustomed to the strange restraints as to manner,
behaviour, and speech, which at first were most irksome,
after her past life of freedom in such matters. The little
neglected mind was opening now to the enjoyment of
beauty and happiness, where at first all had seemed a
blank. Leveson Therlock knew by this time how much more
ignorant and neglected they would have found her, but for
the simple efforts of old Job Kippis during many months.

The next few weeks were busy ones, for Mrs. Therlock
had all sorts of plans for helping the Forsyths, and Lettie's
greatest delight was in seeing those plans carried out. Hor's
long-standing wish to go to sea was at last to be fulfilled,
and when the boy, in a fervour of excitement on hearing the
good news, rushed off to Job Kippis, he listened patiently to
the old man's grave rebuke.

"Will ye say now, boy, that God don't care for ye,—aye,
though ye don't deserve He should? Kind to the unthankful
and evil He be, but take care ye don't tempt Him too far, or
maybe He'll see fit to withdraw His mercies from you."

The Forsyths were no longer to live on in their miserable


home. Two or three airy rooms were found for them in an
airy street, at a short distance, and were simply furnished
by Mrs. Therlock, who undertook also to pay a portion of
the rent. Through Leveson's efforts, regular work was
procured for John Forsyth, and the next move was, by dint
of much exertion and great correspondence, to place the
half-witted boy, Roger, in an idiot asylum.

Things began, as Esther said, to "look up" with them


once more. She was able again to take a pleasure in
neatness and respectability, and her careworn look gave
place to health and cheerfulness. The measure dealt out to
little Lettie in her friendless days was amply repaid—"good
measure, pressed down, shaken together, and running
over."

There were plans also for Job Kippis and Ailie. Mrs.
Therlock was going soon with her two little girls to live in
her country house, and a tiny lodge close to the garden
gate would just do for Job. Ailie should go to the village
school, and learn to read and write and work, and when at
home should take her share in opening the gate, and should
be her grandfather's little housekeeper. For a while it
seemed as if the plan might come to pass, and how eagerly
the three children discussed it in all its bearings need
scarcely be told.

Job did not seem to count upon it much himself,


however. He had rallied slightly from his weakness, but
never enough to be moved from the old garret. He liked to
hear the little ones talking of their country home, and would
listen to their anticipations, but he did not join in them for
himself.

"No, deary, I thinks not," he would say, when Ailie


wanted him to look forward as they were doing. "We'll wait
an' see, but somehow I've a thought that 'tain't that sort o'
country I'll be going to."

And gradually the truth broke upon them all, that it was
even so. Job Kippis, the brave old soldier, who had battled
so cheerily through his long troubled life, was going to
another and farther Land.

They did not think the change so near as it was. But


one rough February evening, a message came to Leveson
Therlock, home on a brief visit,—a message sent by Ailie.

"Grandfather was worse."

Nothing but those three words, implying the need of


Leveson's presence,—and he went.

Job lay there quietly, in his narrow garret, with brown


hands clasped across his chest, as often of late, and a look
of wondrous rest upon his furrowed brow, while Ailie
crouched, trembling, beside the bed. He glanced up cheerily
as Leveson came in.

"It's a stormy night," he said. "I scarce thought I'd see


you, sir, but Ailie she said you was at home, an' she knowed
you'd wish we should send."

"Ailie was right," said Leveson. "It must have been a


storm indeed that could have kept me back if you needed
me. How are you to-night?"

He looked downwards, smiling still, with a little motion


of his hand towards the floor. "Waters of Jordan washin' all
round me, sir, but I ain't out o' my depth yet."

"And you will not be," said Leveson, "so long as you
lean on your Guide. Don't look at the water like Peter, but
look to His Face."

"I'll see it soon,—as plain as I see yours," said Job.

"Would you like me to pray with you?"

"Sure an' I would, sir, if 'tain't troublin' you,—not as


that's likely," he added. "I'm not feared. But if 'tis all the
same to you, sir, I'd rather have the prayers I knows, an'
not the Visitation of the Sick, nor no new one. My head's a
bit weak, an' I'll follow the old words easiest."

So the old-grand sweet words, offered up by tens of


thousands before him through hundreds of years past, now
sounded reverently in Leveson's deep voice. They seemed
to fill the little garret with an atmosphere of peace, and to
bring a ray of measureless trust upon Job's face, as he lay
again with his clasped hands.
"Aye, that be it," he said at the close in an undertone.
"Strayed an' wanderin',—leavin' undone things I ought to
ha' done, an' doin' things I ought to ha' left undone,—a
poor miserable offender first to last. But He 've forgiven me,
—blessed be His Name."

Then Job was quiet awhile,—as if asleep. Presently


looking up, he said, "He 've been a good Master,—a good
Master,—lovin' right to the end."

"And how in the day of trouble, and failure, and almost


starvation?" asked Leveson. "Had He forsaken you then?
Did your faith stand out then?"

"Sure an' if it didn't, 'twas I that failed, an' not He. Trust
Him!—Aye, don't I? Little Ailie—"

She came closer, sobbing, and he put his hand over


hers.

"Don't ye ever forget that. Trust Him whatever He do to


ye—whatever. Don't ye ever question an' doubt. His
dealings with ye are all love, an' faithfulness, an'
tenderness, from beginning to end. Maybe He'll let ye
wander alone, and be half-starved again as He's done afore.
It's all love, I tell ye. Just cling to Him, an' He'll be with ye
through all. He'll never leave ye. He's never left me,—an'
never will."

Once more there came an interval of silence, as Job lay


with that same smile upon his face, and no fear at his
heart, no words of doubt upon his lips. He knew his Master.
Through long years he had proved His love. And now that
the last trial of life had come, he was troubled by no dread.

"Aye, I'll die here," he said, speaking when they thought


him past speech. "Up in the old garret. Didn't think
somehow all along that I'd be let go to the country. I'd learn
to love this world then maybe, an' that 'ud be a pity,
wouldn't it? I don't love it now, nor want nothin' more."

Nothing more on earth. He had nothing more,—except


peace at the last. Slowly, as night crept by, he grew weaker.
Jordan's waters were around him, playing over him, dashing
about him, rising higher and higher as he went deeper into
the flood. But he never sank, never wavered, never
struggled. Passing calmly through their midst, with his
Master by his side, he forded all the waves, and never lost
his footing. And as the first gray tint of dawn was shining in
the east, over the house-tops across the way, Job reached
the Other Side.

He was only a poor old tailor, living up in a garret, in


London's dreariest quarter! But from the midst of squalor
and misery, rags and dirt, sounds of contention and anger,
voices of sorrow and pain,—he passed to glory and joy
unending, to be a king and a priest for ever before the
throne of God.

CHAPTER XXVI.
THE LAST OF THE OLD GARRET.
AND as the light of dawn came into the garret, which
for so many months had formed Job's home,—came resting
in dull shades of gray upon the wall, and upon the face that
lay so calm in death, and upon the outlines of the old
warrior's face, still to be seen over the fireplace,—as the
light increased, Leveson rose to leave. He would take little
Ailie, twice-orphaned child, home with him. Where else
could she go?

But the door creaked slowly open, and a woman stood


there,—a haggard faded woman, walking with difficulty,
dressed in rags, footsore and poverty-stricken.

"They telled me I'd find her here," she said. "They telled
me I'd find Ailie."

And a cry broke from Ailie's lips, ringing through the


stillness of the death-chamber, but never disturbing the
repose of old Job Kippis, lying in his last long sleep,—a cry
of "Mother! Mother!"

"Ailie! Why sure it can't be Ailie," said Mary Carter,


almost putting the child from her at first, as she scanned
her face with trembling eagerness. "Ailie,—why, so it is, but
I scarce knowed ye, child,—ye've that grown an' altered."

"O mother, if you had but come home a little earlier—


just a little," sobbed Ailie. "He's dead now—gran'father's
dead—an' ye'll never be able to thank him."

"Gran'father!" repeated Mary Carter.

"He made me call him so, an' he was more to me nor


any real gran'father. Mother, why did ye never come
sooner?"
"I couldn't help it. 'Twas no choice o' mine. Who's took
care o' ye all these months?"

"Gran'father—old Job Kippis he was," said Ailie


sorrowfully, pointing towards the bed. "He's lyin' there. He
ain't dead long. Oh, I wish ye'd come sooner, an' could ha'
spoken to him."

"Maybe ye haven't a bit of somethin' to give me. I'm


famished."

She looked ready to drop, and Leveson, coming


forwards, told her to sit down on the chair, and desired Ailie
to bring food from the cupboard. She ate eagerly, holding
Ailie all the while, as if fearing to lose her again, and
Leveson said, "It must be almost more than you expected,
to find your little girl safe in the old house."

"Indeed, sir, an' I've wondered what could ha' become


of her, not a soul to look after her, an' her poor father a-
dying the night I went." She heaved a sigh at the
recollection.

"Have you been in any trouble since leaving jail?" asked


Leveson gravely.

She did not answer the question, but flushed with


burning shame at the last word, and hung her head heavily.
"What Jem would ha' said—I doubt but it helped to kill him.
An' my poor mother as brought me up so respectable; but I
didn't know what I was a-doin' that day, I didn't."

"It was the first time you ever gave way to such
temptation, was it not?"

She gave a mute sign of assent.


"And I trust it may be the last. Poor woman, you have
suffered for your sin," he said compassionately. "But there
is One—One of purer eyes than to behold iniquity, and One
whose law you have broken—who well knows the strength
of your temptation. He offers you free pardon for the past,
if you will seek it at His feet."

"I dunno much about such things," said Mary Carter


despondingly. "An' what I'm to do now, no home, an' no
work, an' the child dependin' on me!"

"Mother, we'll be took care of," said Ailie. "Why didn't


you come back straight when you was set free?"

"I couldn't, child. I've been in hospital since. I was run


over that day, an' 'twas weeks afore I knowed where I was,
an' longer afore I could speak sense."

"Run over!" repeated Leveson and Ailie together.

"Aye, 'twas that same day," repeated Mary Carter. "I've


but a half remembrance of it all. I was walkin' along, an'
looking forward to hear where Ailie was, an' thinkin' to find
she'd been sent off to the work'us. I s'pose I wasn't heedin'
much where I was goin', an' in crossin' a road, I heard a
shriekin', and I see a great 'bus comin' down right upon me,
an' somehow my foot slipped. After that I knowed nothin'—
for weeks they telled me. I'd a broken leg, an' a blow on the
head, as took away all my senses. It's left me that weak
now, that I don't scarce know how to walk nor stand, but
they says I'm as well as I'm like to be for many a year. I'll
never be the same woman again, an' I can't take a needle
for half an hour, but I turns giddy. But I'll have to work, for
we ain't got nothin' to live on."

"We will not leave you to starve," said Leveson. "I think
we shall find some means of helping you. Now, what will
you do first? I would rather see you in another room before
I go. Is there any vacant in the house, Ailie?"

"Please, sir, next door garret. Mr. Sloane went away


yesterday," said Ailie, "an' nobody hasn't took it yet."

"Then I think that had better be your home for a few


days, until we can arrange something more definite."

He placed five shillings in Mary Carter's hand as he


spoke, and she faltered tearful thanks. There were a few
words more about arrangements. Then he walked to the
bedside, and stood looking down—not sadly. It was not a
sight to look upon sadly—that face of happy rest.

"Fought a good fight, kept the faith, finished the


course," he murmured. "Poor old Kippis! Oh, what a change
to step from such a spot as this into the infinite glory! Ailie,
—" and he laid his hand on the little girl's head,—"never
forget all that he taught you. Never forget to pray that your
last end may be like his."

And Leveson went home. But all the way he had ringing
in his head the words of a hymn, which seemed strangely
applicable to old Job:—

"Safe home, safe home in port!


Rent cordage, shattered deck,
Torn sails, provisions short,
And only not a wreck.
But oh! the joy upon the shore,
To tell our voyage perils o'er.

"The prize, the prize secure,


The athlete nearly fell,
Bare all he could endure,
And bare not always well;
But he may smile at troubles gone
Who sets the victor garland on."

CHAPTER XXVII.
A NEW HOME.

IT was a lovely day, out in the fair country, far away


from the smoke and dust, the noise and turmoil, which had
surrounded Ailie from earliest babyhood. Through the drive
from the station, Ailie sat beside her mother in the farmer's
cart which had been sent to meet them, wondering till
words failed her at all she saw.

The green early grass stretching into the far distance,


the purple horizon tints, the budding richness of hedges
near at hand, the glee of birds overhead, the lowing of cows
in the meadows, the gay frisking of tiny lambs beside their
staid old mothers, the harsh cawing of rooks in old elm
trees—what a marvellous world it was!
Ailie's pent-up delight broke forth in one eager cry: "O
mother! Just think o' livin' here!"

"Seems a dream to me, to be seeing a green field


again, it do," said Mary Carter.

"O mother, don't it look as if there was room here?" said


Ailie. "An' not every one a-crowdin' an' pushin' everybody!
Why, it looks most as if the world was gettin' empty."

"Ah, you be come from London parts," said the stout


driver in his smock frock, who had been whistling a
nameless tune, and letting his plump horse jog along
quietly at any pace it chose. "Lots o' folks in London, ain't
there, an' not much o' green fields?"

"I never see a green field in all my life afore," said Ailie,
upon which the worthy man ejaculated—

"Think o' that now! Never see a green field!" and gazed
at Ailie with compassion.

"O mother,—see, there be a brown field too!" cried Ailie.


"What's it for?"

"That be sown with wheat," said the man. "Ye'll see it all
a-comin' up by an' by. An' there, over among the trees, is
the house I'm a-takin' ye to—Mrs. Therlock's."

"An' she lives there?" said Ailie.

"That she do,—an' her father an' grandfather afore her.


A mighty kind lady she be, and we're main glad to have her
among us again, with little Miss Vi and all."

Passing by a plantation of saplings growing close to the


road, a small gate in the fence opened, and two little girls
rushed out. "I knew it was them," cried Josie. "I knew it,
directly I heard the cart. O stop, please—don't drive on. Let
them both get down here. What do you think of the country,
Ailie?"

The man pulled up slowly, threw the reins on the old


horse's neck, stepped down himself first, lifted Ailie to the
ground, and helped her mother to follow. Ailie gazed
wonderingly round, and back at Josie.

"Well?" repeated Josie. "You look as puzzled as Vi did,


when first we came. But you like it now, don't you, Vi?"

"It's just beautiful," said little Vi emphatically. "Ever so


much better than the old court, ain't it, Ailie?"

Ailie nodded. Words would not come yet. "Mother will


see you soon," said Josie, assuming the patronizing "Miss
Therlock" air, which she sometimes put on. "And now I am
going to show you your new home. Come along, Vi,—we'll
lead the way."

Holding Vi's hand, as if she counted her little sister her


especial charge, Josie danced along the grass borders,
looking back impatiently at Mary Carter's slower footsteps.

"It's not far," she said, "only along the road,—straight


on this way. After all, you might as well have kept in the
cart, but it doesn't matter. We're close now. Only this one
corner. There!"

They had reached the large iron gates which formed the
principal entrance to the grounds. Beside them stood a
fancy cottage, small and neat, overgrown by honeysuckle
and clematis. One lattice window below and one above
looked towards the road, and a tiny garden, stocked with
early vegetables, lay on one side. Ailie's eyes went
speechlessly to her mother and to Josie.

"Yes, that's it," said Josie. "That is to be your own home


now. And all you've got to do is to open and shut the gate,
Mrs. Carter, when a carriage passes through. But mother
will tell you all that by and by. Come now,—come in and see
how you like the rooms."

Following the eager child, Ailie and her mother found


themselves in a neat kitchen, furnished with a strong deal
table, two wooden chairs, and a small dresser which bore
an ample supply of blue china and other requisites. Nothing
would satisfy Josie but that they must at once climb the
ladder staircase, into the upper room, and there admire the
tidy bed, the chintz curtains, the painted wooden chest of
drawers, and the washhand-stand, with its jug and basin.
She chattered fast enough herself to make up for their
bewildered silence, and as soon as she had done displaying
the bedroom, she brought them down again.

"I think I have shown you all now, Mrs. Carter."

Poor Mary could do nothing but curtsey in her wordless


gratitude.

"And mother has put some tea in this little box, and
there's the teapot up there, and Vi and I brought some milk
and bread and butter ourselves this afternoon, didn't we,
Vi? So you can have your tea as soon as you like. Shall I tell
mother you are pleased?"

Assurances on this point were so unnecessary, while in


full view of those two faces, that Josie did not wait for
them, and went springing away along the gravel pathway,
the long ribbon ends of her hat floating out in the breeze.
Lettie lingered behind, looking sedately at Ailie.
"It's just like a dream, so it be," said Mary Carter,
slowly. "Such a place as this! Why, I don't know if I'm in my
senses to think it's for us."

"It's just beautiful!" said Ailie, with one long breath.

"An' I haven't said a word o' thanks," said Mary. "I


couldn't. Seemed as if none 'ud come. But Miss Vi 'll tell the
lady,—won't ye, Miss? I can't say all I ought."

"I'll tell mamma you're glad," said Lettie, adding


thoughtfully,—"Ailie, don't you wish ever so much that old
gran'father was here?"

"He'd ha' liked the green grass, an' the trees' an' the
flowers," said Ailie.

"Mamma says heaven's ever so much beautifuller than


the country," said Lettie. "I don't know how, but she says it
is."

"Gran'father didn't seem to want to come, 'cause he


was afraid he'd learn to love it more than heaven," said
Ailie. "I hope we won't,—but I do think it'll be hard not to,"
she added, looking through the window at the sunshine
without. "It do seem pretty."

"Maybe if we try, we won't neither," said Lettie. "Josie


will want me, and I'll go now."

Smiling a farewell, she too went off along the gravel


path, in somewhat more sober fashion than Josie.

Ailie stood gazing after the little departing figure,


thinking to herself how she would need to know and love
and trust God much, even as old Job Kippis had known and
loved and trusted, if she would keep the thought of Heaven
first in her heart, before the thought of this her new sweet
cottage-home.

THE END.
*** END OF THE PROJECT GUTENBERG EBOOK THE OLD HOUSE IN
THE CITY ***

Updated editions will replace the previous one—the old editions will
be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States copyright in
these works, so the Foundation (and you!) can copy and distribute it
in the United States without permission and without paying
copyright royalties. Special rules, set forth in the General Terms of
Use part of this license, apply to copying and distributing Project
Gutenberg™ electronic works to protect the PROJECT GUTENBERG™
concept and trademark. Project Gutenberg is a registered trademark,
and may not be used if you charge for an eBook, except by following
the terms of the trademark license, including paying royalties for use
of the Project Gutenberg trademark. If you do not charge anything
for copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such as
creation of derivative works, reports, performances and research.
Project Gutenberg eBooks may be modified and printed and given
away—you may do practically ANYTHING in the United States with
eBooks not protected by U.S. copyright law. Redistribution is subject
to the trademark license, especially commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the free


distribution of electronic works, by using or distributing this work (or
any other work associated in any way with the phrase “Project
Gutenberg”), you agree to comply with all the terms of the Full
Project Gutenberg™ License available with this file or online at
www.gutenberg.org/license.

Section 1. General Terms of Use and


Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand, agree
to and accept all the terms of this license and intellectual property
(trademark/copyright) agreement. If you do not agree to abide by all
the terms of this agreement, you must cease using and return or
destroy all copies of Project Gutenberg™ electronic works in your
possession. If you paid a fee for obtaining a copy of or access to a
Project Gutenberg™ electronic work and you do not agree to be
bound by the terms of this agreement, you may obtain a refund
from the person or entity to whom you paid the fee as set forth in
paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only be


used on or associated in any way with an electronic work by people
who agree to be bound by the terms of this agreement. There are a
few things that you can do with most Project Gutenberg™ electronic
works even without complying with the full terms of this agreement.
See paragraph 1.C below. There are a lot of things you can do with
Project Gutenberg™ electronic works if you follow the terms of this
agreement and help preserve free future access to Project
Gutenberg™ electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright law
in the United States and you are located in the United States, we do
not claim a right to prevent you from copying, distributing,
performing, displaying or creating derivative works based on the
work as long as all references to Project Gutenberg are removed. Of
course, we hope that you will support the Project Gutenberg™
mission of promoting free access to electronic works by freely
sharing Project Gutenberg™ works in compliance with the terms of
this agreement for keeping the Project Gutenberg™ name associated
with the work. You can easily comply with the terms of this
agreement by keeping this work in the same format with its attached
full Project Gutenberg™ License when you share it without charge
with others.

1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the
terms of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.

1.E. Unless you have removed all references to Project Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project Gutenberg™
work (any work on which the phrase “Project Gutenberg” appears,
or with which the phrase “Project Gutenberg” is associated) is
accessed, displayed, performed, viewed, copied or distributed:
This eBook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this eBook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.

1.E.2. If an individual Project Gutenberg™ electronic work is derived


from texts not protected by U.S. copyright law (does not contain a
notice indicating that it is posted with permission of the copyright
holder), the work can be copied and distributed to anyone in the
United States without paying any fees or charges. If you are
redistributing or providing access to a work with the phrase “Project
Gutenberg” associated with or appearing on the work, you must
comply either with the requirements of paragraphs 1.E.1 through
1.E.7 or obtain permission for the use of the work and the Project
Gutenberg™ trademark as set forth in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is posted


with the permission of the copyright holder, your use and distribution
must comply with both paragraphs 1.E.1 through 1.E.7 and any
additional terms imposed by the copyright holder. Additional terms
will be linked to the Project Gutenberg™ License for all works posted
with the permission of the copyright holder found at the beginning
of this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files containing a
part of this work or any other work associated with Project
Gutenberg™.

1.E.5. Do not copy, display, perform, distribute or redistribute this


electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1
with active links or immediate access to the full terms of the Project
Gutenberg™ License.

1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™ works
unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or providing


access to or distributing Project Gutenberg™ electronic works
provided that:

• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”

• You provide a full refund of any money paid by a user who


notifies you in writing (or by e-mail) within 30 days of receipt
that s/he does not agree to the terms of the full Project
Gutenberg™ License. You must require such a user to return or
destroy all copies of the works possessed in a physical medium
and discontinue all use of and all access to other copies of
Project Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full refund of


any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project Gutenberg™


electronic work or group of works on different terms than are set
forth in this agreement, you must obtain permission in writing from
the Project Gutenberg Literary Archive Foundation, the manager of
the Project Gutenberg™ trademark. Contact the Foundation as set
forth in Section 3 below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on, transcribe
and proofread works not protected by U.S. copyright law in creating
the Project Gutenberg™ collection. Despite these efforts, Project
Gutenberg™ electronic works, and the medium on which they may
be stored, may contain “Defects,” such as, but not limited to,
incomplete, inaccurate or corrupt data, transcription errors, a
copyright or other intellectual property infringement, a defective or
damaged disk or other medium, a computer virus, or computer
codes that damage or cannot be read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except for


the “Right of Replacement or Refund” described in paragraph 1.F.3,
the Project Gutenberg Literary Archive Foundation, the owner of the
Project Gutenberg™ trademark, and any other party distributing a
Project Gutenberg™ electronic work under this agreement, disclaim
all liability to you for damages, costs and expenses, including legal
fees. YOU AGREE THAT YOU HAVE NO REMEDIES FOR
NEGLIGENCE, STRICT LIABILITY, BREACH OF WARRANTY OR
BREACH OF CONTRACT EXCEPT THOSE PROVIDED IN PARAGRAPH
1.F.3. YOU AGREE THAT THE FOUNDATION, THE TRADEMARK
OWNER, AND ANY DISTRIBUTOR UNDER THIS AGREEMENT WILL
NOT BE LIABLE TO YOU FOR ACTUAL, DIRECT, INDIRECT,
CONSEQUENTIAL, PUNITIVE OR INCIDENTAL DAMAGES EVEN IF
YOU GIVE NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you


discover a defect in this electronic work within 90 days of receiving
it, you can receive a refund of the money (if any) you paid for it by
sending a written explanation to the person you received the work
from. If you received the work on a physical medium, you must
return the medium with your written explanation. The person or
entity that provided you with the defective work may elect to provide
a replacement copy in lieu of a refund. If you received the work
electronically, the person or entity providing it to you may choose to
give you a second opportunity to receive the work electronically in
lieu of a refund. If the second copy is also defective, you may
demand a refund in writing without further opportunities to fix the
problem.

1.F.4. Except for the limited right of replacement or refund set forth
in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of damages.
If any disclaimer or limitation set forth in this agreement violates the
law of the state applicable to this agreement, the agreement shall be
interpreted to make the maximum disclaimer or limitation permitted
by the applicable state law. The invalidity or unenforceability of any
provision of this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the Foundation,


the trademark owner, any agent or employee of the Foundation,
anyone providing copies of Project Gutenberg™ electronic works in
accordance with this agreement, and any volunteers associated with
the production, promotion and distribution of Project Gutenberg™
electronic works, harmless from all liability, costs and expenses,
including legal fees, that arise directly or indirectly from any of the
following which you do or cause to occur: (a) distribution of this or
any Project Gutenberg™ work, (b) alteration, modification, or
additions or deletions to any Project Gutenberg™ work, and (c) any
Defect you cause.

Section 2. Information about the Mission


of Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new computers.
It exists because of the efforts of hundreds of volunteers and
donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project Gutenberg™’s
goals and ensuring that the Project Gutenberg™ collection will
remain freely available for generations to come. In 2001, the Project
Gutenberg Literary Archive Foundation was created to provide a
secure and permanent future for Project Gutenberg™ and future
generations. To learn more about the Project Gutenberg Literary
Archive Foundation and how your efforts and donations can help,
see Sections 3 and 4 and the Foundation information page at
www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-profit
501(c)(3) educational corporation organized under the laws of the
state of Mississippi and granted tax exempt status by the Internal
Revenue Service. The Foundation’s EIN or federal tax identification
number is 64-6221541. Contributions to the Project Gutenberg
Literary Archive Foundation are tax deductible to the full extent
permitted by U.S. federal laws and your state’s laws.

The Foundation’s business office is located at 809 North 1500 West,


Salt Lake City, UT 84116, (801) 596-1887. Email contact links and up
to date contact information can be found at the Foundation’s website
and official page at www.gutenberg.org/contact

Section 4. Information about Donations to


the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission of
increasing the number of public domain and licensed works that can
be freely distributed in machine-readable form accessible by the
widest array of equipment including outdated equipment. Many
small donations ($1 to $5,000) are particularly important to
maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws regulating


charities and charitable donations in all 50 states of the United
States. Compliance requirements are not uniform and it takes a
considerable effort, much paperwork and many fees to meet and
keep up with these requirements. We do not solicit donations in
locations where we have not received written confirmation of
compliance. To SEND DONATIONS or determine the status of
compliance for any particular state visit www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states where


we have not met the solicitation requirements, we know of no
prohibition against accepting unsolicited donations from donors in
such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot make


any statements concerning tax treatment of donations received from
outside the United States. U.S. laws alone swamp our small staff.

Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.

Section 5. General Information About


Project Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could be
freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose network of
volunteer support.
Project Gutenberg™ eBooks are often created from several printed
editions, all of which are confirmed as not protected by copyright in
the U.S. unless a copyright notice is included. Thus, we do not
necessarily keep eBooks in compliance with any particular paper
edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg Literary
Archive Foundation, how to help produce our new eBooks, and how
to subscribe to our email newsletter to hear about new eBooks.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookmass.com

You might also like