Вы находитесь на странице: 1из 67

iOS Architecture Patterns: MVC, MVP,

MVVM, VIPER, and VIP in Swift 1st


Edition Raúl Ferrer García
Visit to download the full and correct content document:
https://ebookmass.com/product/ios-architecture-patterns-mvc-mvp-mvvm-viper-and-vi
p-in-swift-1st-edition-raul-ferrer-garcia/
iOS Architecture
Patterns
MVC, MVP, MVVM, VIPER, and
VIP in Swift

Raúl Ferrer García
iOS Architecture
Patterns
MVC, MVP, MVVM, VIPER,
and VIP in Swift

Raúl Ferrer García


iOS Architecture Patterns: MVC, MVP, MVVM, VIPER, and VIP in Swift
Raúl Ferrer García
Barcelona, Spain

ISBN-13 (pbk): 978-1-4842-9068-2 ISBN-13 (electronic): 978-1-4842-9069-9


https://doi.org/10.1007/978-1-4842-9069-9

Copyright © 2023 by Raúl Ferrer García


This work is subject to copyright. All rights are reserved 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.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark
symbol with every occurrence of a trademarked name, logo, or image we use the names, logos,
and images only in an editorial fashion and to the benefit of the trademark owner, with no
intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if
they are not identified as such, is not to be taken as an expression of opinion as to whether or not
they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of
publication, neither the authors nor the editors nor the publisher can accept any legal
responsibility for any errors or omissions that may be made. The publisher makes no warranty,
express or implied, with respect to the material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Aaron Black
Development Editor: James Markham
Coordinating Editor: Jessica Vakili
Cover image designed by Freepik (www.freepik.com)
Distributed to the book trade worldwide by Springer Science+Business Media New York, 1
New York Plaza, Suite 4600, New York, NY 10004-1562, USA. Phone 1-800-SPRINGER, fax (201)
348-4505, e-mail orders-ny@springer-sbm.com, or visit www.springeronline.com. Apress Media,
LLC is a California LLC and the sole member (owner) is Springer Science + Business Media
Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
For information on translations, please e-mail booktranslations@springernature.com; for
reprint, paperback, or audio rights, please e-mail bookpermissions@springernature.com.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook
versions and licenses are also available for most titles. For more information, reference our Print
and eBook Bulk Sales web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is
available to readers on the Github repository: https://github.com/Apress/iOS-Architecture-
Patterns. For more detailed information, please visit http://www.apress.com/source-code.
Printed on acid-free paper
We’re here to put a dent in the universe. Otherwise,
why else even be here?
—Steve Jobs

They didn’t know it was impossible, so they did it.


—Mark Twain
Table of Contents
About the Author���������������������������������������������������������������������������������xi

About the Technical Reviewer�����������������������������������������������������������xiii

Acknowledgments������������������������������������������������������������������������������xv

Introduction��������������������������������������������������������������������������������������xvii

Chapter 1: Introduction������������������������������������������������������������������������1
What Is Software Architecture?����������������������������������������������������������������������������2
Architecture Patterns��������������������������������������������������������������������������������������������3
Why Do We Need an Architecture Pattern for Our Applications?��������������������������3
Design from High Level to Low Level��������������������������������������������������������������������5
Design Patterns�����������������������������������������������������������������������������������������������6
SOLID Principles��������������������������������������������������������������������������������������������10
How to Choose the Right Architectural Pattern���������������������������������������������������11
Most Used Architecture Patterns�������������������������������������������������������������������13
In Search of a “Clean Architecture”��������������������������������������������������������������������14
Clean Architecture Layers������������������������������������������������������������������������������14
The Dependency Rule������������������������������������������������������������������������������������17
Advantages of Applying a Clean Architecture������������������������������������������������17
MyToDos: A Simple App to Test Architectures�����������������������������������������������������18
App Screens��������������������������������������������������������������������������������������������������18
App Development������������������������������������������������������������������������������������������28
Summary������������������������������������������������������������������������������������������������������������43

v
Table of Contents

Chapter 2: MVC: Model–View–Controller��������������������������������������������45


What Is MVC?������������������������������������������������������������������������������������������������������45
A Little History�����������������������������������������������������������������������������������������������45
Apple Model–View–Controller�����������������������������������������������������������������������46
Components in MVC��������������������������������������������������������������������������������������������47
Model�������������������������������������������������������������������������������������������������������������47
View���������������������������������������������������������������������������������������������������������������48
Controller�������������������������������������������������������������������������������������������������������49
Advantages and Disadvantages of MVC��������������������������������������������������������������49
Advantages of the MVC Pattern���������������������������������������������������������������������49
Disadvantages of the MVC Pattern����������������������������������������������������������������50
MVC Application��������������������������������������������������������������������������������������������������51
MVC Layers����������������������������������������������������������������������������������������������������51
MyToDos Application Screens�����������������������������������������������������������������������64
Testing�����������������������������������������������������������������������������������������������������������89
Summary����������������������������������������������������������������������������������������������������������105

Chapter 3: MVP: Model–View–Presenter������������������������������������������107


What Is MVP?����������������������������������������������������������������������������������������������������107
A Little History���������������������������������������������������������������������������������������������107
How It Works�����������������������������������������������������������������������������������������������107
Components in MVP������������������������������������������������������������������������������������108
Advantages and Disadvantages of the MVP������������������������������������������������111
MVP Application������������������������������������������������������������������������������������������������112
MVP Layers��������������������������������������������������������������������������������������������������112
MyToDos Application Screens���������������������������������������������������������������������116
MVP-MyToDos Testing���������������������������������������������������������������������������������139
Summary����������������������������������������������������������������������������������������������������������144

vi
Table of Contents

Chapter 4: MVVM: Model–View–ViewModel�������������������������������������145


What Is MVVM?�������������������������������������������������������������������������������������������������145
A Little History���������������������������������������������������������������������������������������������145
How It Works�����������������������������������������������������������������������������������������������145
Components in MVVM���������������������������������������������������������������������������������146
Advantages and Disadvantages of MVVM���������������������������������������������������������148
Advantages��������������������������������������������������������������������������������������������������149
Disadvantages���������������������������������������������������������������������������������������������149
MVVM Application���������������������������������������������������������������������������������������������150
MVVM Layers�����������������������������������������������������������������������������������������������151
MyToDos Data Binding���������������������������������������������������������������������������������155
MyToDos Application Screens���������������������������������������������������������������������164
MVVM-MyToDos Testing������������������������������������������������������������������������������198
MVVM-C: Model–View–ViewModel–Coordinator�����������������������������������������������206
What Is a Coordinator?��������������������������������������������������������������������������������206
Using MVVM-C in MyToDos��������������������������������������������������������������������������208
Summary����������������������������������������������������������������������������������������������������������224

Chapter 5: VIPER: View–Interactor–Presenter–Entity–Router����������225


What Is VIPER?��������������������������������������������������������������������������������������������������225
A Little History���������������������������������������������������������������������������������������������225
How It Works�����������������������������������������������������������������������������������������������226
Components in VIPER����������������������������������������������������������������������������������226
Advantages and Disadvantages of VIPER����������������������������������������������������228
VIPER Application����������������������������������������������������������������������������������������������230
Communication Between Components�������������������������������������������������������230
VIPER Layers������������������������������������������������������������������������������������������������234

vii
Table of Contents

MyToDos Application Screens���������������������������������������������������������������������236


VIPER-MyToDos Testing�������������������������������������������������������������������������������275
Summary����������������������������������������������������������������������������������������������������������282

Chapter 6: VIP: View–Interactor–Presenter��������������������������������������285


What Is VIP?������������������������������������������������������������������������������������������������������285
A Little History���������������������������������������������������������������������������������������������285
How It Works�����������������������������������������������������������������������������������������������285
Components in VIP���������������������������������������������������������������������������������������286
Advantages and Disadvantages of VIP��������������������������������������������������������293
VIP Layers����������������������������������������������������������������������������������������������������294
MyToDos Application Screens���������������������������������������������������������������������296
VIP-MyToDos Testing�����������������������������������������������������������������������������������351
Summary����������������������������������������������������������������������������������������������������������364

Chapter 7: Other Architecture Patterns��������������������������������������������365


Introduction�������������������������������������������������������������������������������������������������������365
RIBs: Router, Interactor, and Builder������������������������������������������������������������������366
A Little History���������������������������������������������������������������������������������������������366
How It Works�����������������������������������������������������������������������������������������������367
Components������������������������������������������������������������������������������������������������368
Advantages and Disadvantages������������������������������������������������������������������370
The Elm Architecture�����������������������������������������������������������������������������������������371
A Little History���������������������������������������������������������������������������������������������371
How It Works�����������������������������������������������������������������������������������������������372
Components������������������������������������������������������������������������������������������������373
Advantages and Disadvantages������������������������������������������������������������������373

viii
Table of Contents

Redux����������������������������������������������������������������������������������������������������������������374
A Little History���������������������������������������������������������������������������������������������374
How It Works�����������������������������������������������������������������������������������������������375
Components������������������������������������������������������������������������������������������������375
Advantages and Disadvantages������������������������������������������������������������������������377
Advantages��������������������������������������������������������������������������������������������������377
Disadvantages���������������������������������������������������������������������������������������������378
TCA: The Composable Architecture�������������������������������������������������������������������378
A Little History���������������������������������������������������������������������������������������������378
How It Works�����������������������������������������������������������������������������������������������379
Components������������������������������������������������������������������������������������������������381
Advantages and Disadvantages������������������������������������������������������������������������382
Advantages��������������������������������������������������������������������������������������������������383
Disadvantages���������������������������������������������������������������������������������������������383
Summary����������������������������������������������������������������������������������������������������������384

Chapter 8: Conclusion�����������������������������������������������������������������������385
The Importance of Clean Architecture���������������������������������������������������������������385
Moving Forward������������������������������������������������������������������������������������������������386

Index�������������������������������������������������������������������������������������������������389

ix
About the Author
Raúl Ferrer García holds a doctorate in
chemistry, but he has always had a great
interest in the world of computer science
and software development, where he began
his foray programming with a ZX Spectrum
at the age of 14. For just over ten years, and
in a self-taught way, he has entered the
world of mobile development, first as an iOS
Developer and then as Mobile Tech Lead at
Editorial Vicens Vives, and he has dedicated
himself completely to the development and
management of mobile applications. He also maintains a blog in which
he tries to explain everything he’s learned and studied about the world of
mobile development.

xi
About the Technical Reviewer
Massimo Nardone has more than 25 years
of experience in security, web and mobile
development, cloud, and IT architecture. His
true IT passions are security and Android. He
has been programming and teaching how to
program with Android, Perl, PHP, Java, VB,
Python, C/C++, and MySQL for more than 20
years. He holds a Master of Science degree
in Computing Science from the University of
Salerno, Italy.
He has worked as a CISO, CSO, security executive, IoT executive,
project manager, software engineer, research engineer, chief security
architect, PCI/SCADA auditor, and senior lead IT security/cloud/SCADA
architect for many years. His technical skills include security, Android,
cloud, Java, MySQL, Drupal, Cobol, Perl, web and mobile development,
MongoDB, D3, Joomla, Couchbase, C/C++, WebGL, Python, Pro Rails,
Django CMS, Jekyll, Scratch, and more.
He worked as visiting lecturer and supervisor for exercises at the
Networking Laboratory of the Helsinki University of Technology (Aalto
University). He holds four international patents (PKI, SIP, SAML, and Proxy
areas). He is currently working for Cognizant as head of cybersecurity
and CISO to help both internally and externally with clients in areas of
information and cybersecurity, like strategy, planning, processes, policies,
procedures, governance, awareness, and so forth. In June 2017, he became
a permanent member of the ISACA Finland Board.

xiii
About the Technical Reviewer

Massimo has reviewed more than 45 IT books for different publishing


companies and is the co-author of Pro Spring Security: Securing Spring
Framework 5 and Boot 2-based Java Applications (Apress, 2019), Beginning
EJB in Java EE 8 (Apress, 2018), Pro JPA 2 in Java EE 8 (Apress, 2018), and
Pro Android Games (Apress, 2015).

xiv
Acknowledgments
First of all, I would like to thank my family for their support, their words of
encouragement, their inspiration… during the preparation and writing of
this book and, in general, ever since. This book is dedicated to them.
Second, I would like to thank the entire Apress team for the
opportunity to write this book, starting with Aaron Black who contacted
me and raised the possibility of writing a book on iOS development, and
not forgetting Jessica Vakili and Nirmal Selvaraj for their great work in
managing and editing this book.
Learning is a journey that never ends, so I would also like to thank
the work of all those who in one way or another teach us something new
every day.
Finally, thanks to you, reader. I hope that once you have read this book
you consider it a wise decision and that, to a greater or lesser extent, it has
helped you in your evolution as a developer.

xv
Introduction
As we will see throughout the book, various architectural patterns have
been developed to apply in the development of our applications – some
well known (and older), such as MVC or MVVM, and others more
innovative, such as VIPER or VIP.
If you are just starting to develop applications or have been at it
for some time, you have surely searched for information on how an
application is built and what architecture pattern is the best to apply.
But possibly you have also reached the same conclusion as me: from a
global point of view, there is no perfect architecture pattern, they all have
advantages and disadvantages, and it almost always depends on how we
apply said pattern that our code is readable, testable, and scalable.
In addition, you will also have noticed that an architecture pattern
comes to mark some kind of application rules, but that later many
developers adapt or modify it looking to improve its features or solve some
of its possible drawbacks.

Who Is This Book For?


This book is aimed both at those developers who are starting now and
who want to know what architecture patterns they can apply to their
applications, as well as those developers who have been developing
applications for some time but who want to know other possible
architectures to apply.

xvii
Introduction

Therefore, this book is for you if what you want is

• Learn to develop applications following some of the


architecture patterns explained

• Understand the advantages and disadvantages of each


of the architecture patterns explained and choose the
one that suits you best

• Understand the advantages of developing a readable,


testable, and scalable code

In this book I have not sought to delve into the use of each of the
architectures explained, but rather to serve as a point of introduction to
their use, to understand why they are important, and from here on you will
be able to choose one or those that suit you best, know how to delve into
them, apply them, and evolve in your career as a developer.

How to Use This Book?


Apart from a theoretical introduction to each of the architectural patterns
presented (there are numerous articles for each of the architectures
that we will cover that talk about their features, advantages, and
disadvantages), this book is eminently practical. In Chapters 2–6 (MVC,
MVP, MVVM, VIPER, and VIP architecture patterns), the development of
an application (MyToDos) following each of these patterns is presented.
For the sake of simplicity, although the main parts of the code are
presented (depending on the concept explained), you will be able to
observe omitted parts of the code (marked with “...”). However, you can
find the full code for each of the projects in this book’s repository.
Therefore, I am going to assume that you have some knowledge of both
Swift and Xcode that should allow you to follow the course of the book
without problems.

xviii
CHAPTER 1

Introduction
Assume the following situation: you and your team have received a new
project to develop a mobile application. A project, whether it originates
from our idea or is commissioned by a client, will present a series of
specifications, functionalities, behaviors, etc.
Continuing with our assumption, we are going to consider that all
these specifications and functionalities have already been studied and
transformed into user stories (i.e., how a functionality would be described
from the point of view of a user: for example, “As a user, I want to login
in the application”) and that we could already start developing the
application by writing the first lines of code.
It has happened to all of us that when we have a new project, we want
to start writing code. However, if we work in this way, without proposing a
project structure or taking into account the type of application, we can end
up developing an application that works, but whose code is later difficult to
maintain.
To avoid this situation, before starting to write code we have to
determine what structure we are going to give it, what the Software
Architecture is going to be, and what architecture pattern is the most
suitable for our project.
Before starting to see the most used architecture patterns in the
development of iOS applications, we are going to make an introduction to
what Software Architecture is, what architecture patterns are, why their use
is necessary, and how to choose the most suitable one for our projects.

© Raúl Ferrer García 2023 1


R. Ferrer García, iOS Architecture Patterns, https://doi.org/10.1007/978-1-4842-9069-9_1
Chapter 1 Introduction

What Is Software Architecture?


The Software Architecture defines how the software structure is, what
are the components that form it, how they are joined, and how they
communicate with each other.
All these points that intervene in the definition of the Software
Architecture can be represented according to different models or
views, the following three being the main ones (and an example of their
application is one of the architectures that we will study later, the MVVM
or Model–View–ViewModel):

• Static view: It indicates which components make up


the structure. In MVVM, these components would be
View, Model, and ViewModel.

• Dynamic view: It establishes the behavior of the


different components and the communication between
them over time.

• Functional view: It shows us what each component


does. For example, in the example we are seeing,
each of the components would have the following
functionalities:

• Model: It contains the classes and structures


responsible for storing and transferring an
application’s data. It also includes business logic.

• View: It represents the interface with the elements


that form it, the interaction with the user, and how
it is updated to show the user the information
received.

2
Chapter 1 Introduction

• ViewModel: It acts as an intermediary between


the View and the Model; it usually includes
presentation logic, that is, those methods that allow
the data received from the Model to be transformed
to be presented in the View.

Architecture Patterns
We have just seen that Software Architecture helps us to give structure
to our project. However, not all projects are the same or have the same
purpose, so, logically, the architectures used are different and appropriate
to each project.
Developers have been finding different solutions when facing their
projects. The fact that the requirements and functionalities of a project, its
components, or the way of communicating between them vary from one
project to another has given rise to different architectural solutions and
architecture patterns.
Keep in mind that an architecture pattern is like a template that
offers us some rules or guidelines on how to develop and structure the
different components of the application. Each architectural pattern has its
advantages and disadvantages, as we will see later.

 hy Do We Need an Architecture Pattern


W
for Our Applications?
The selection and use of an architecture pattern when developing our
applications will allow us to avoid a series of problems that applications
that have been developed without using these patterns can present.

3
Chapter 1 Introduction

Some of these problems are as follows:

• These are applications that are difficult to maintain.


This problem increases if new developers are involved,
as it is more costly for them to understand the software
they are working on.

• It usually increases the development time and,


therefore, increases its cost.

• As it is not a structured code, it is more complicated to


add new features or scale it.

• They are very likely to have duplicate, unused, and


messy code. All this makes it more prone to errors.

Therefore, the use of a good architecture pattern will allow us to reduce


these problems:

• We will work with a code that is simpler, more


organized, and easier to understand (and following
good development practices, such as the SOLID
principles) for all developers since they will act
according to the same rules.
• The written code will be easily testable and less prone
to errors.

• A correct distribution of the components and their


responsibilities will lead to a structure that is easy to
maintain, modify, and extend.

• All of this will result in reduced development time and,


by extension, reduced costs.

4
Chapter 1 Introduction

Design from High Level to Low Level


In this book, we are going to study and apply different architectural
patterns in iOS applications, so we will also see the code with which we
implement them and the best way to implement it.
As we have seen, an architecture pattern gives us guidelines to build an
application that is efficient, scalable, and easy to maintain, among other
advantages.
But we can think of an architecture pattern as the high-level design of
the application, and then we have to go down to the code (Figure 1-1).
This is where the design patterns and their implementation through
the programming language come in, trying to follow some principles
(SOLID), which will make the code flexible, stable, maintainable, and
reusable.

Figure 1-1. Levels of design and implementation in an application

Let’s see briefly what design patterns are (some of which we will apply)
and how to work following the SOLID principles.

5
Chapter 1 Introduction

Design Patterns
In the same way that an architecture pattern is a generic solution to a
certain problem when it comes to the structure of our software (i.e., it will
affect the entire project), design patterns give us solutions to recurring
problems that affect a project component.
There are 23 design patterns, which are described in the book Design
Patterns: Elements of Reusable Object-Oriented Software.1 They described
the 23 design patterns and classified them into three groups: structural
patterns, creational patterns, and behavioral patterns.

Creational Patterns
Creational patterns are those that allow us to create objects. These patterns
encapsulate the procedure for creating an object and generally work
through interfaces.

Factory Method
It provides an interface that allows you to create objects in a superclass, but
delegates the implementation and alteration of objects to subclasses.

Abstract Factory
It provides an interface that allows groups of related objects to be
generated, but without specifying their specific classes or implementation.

1
Design Patterns: Elements of Reusable Object-Oriented Software by E. Gamma,
R. Helm, E. Johnson, and J. Vlissides. Addison Wesley, 1st Ed, 1994.

6
Chapter 1 Introduction

Builder
It allows building complex objects step by step, separating the creation of
the object from its structure. In this way, we can use the same construction
process to obtain different types and representations of an object.

Singleton
This pattern ensures that a class has only one possible instance, which is
globally accessible.

Prototype
It allows you to copy or clone an object without requiring our code to
depend on its classes.

Structural Patterns
Structural patterns specify how objects and classes relate to each other to
form more complex structures so that they are flexible and efficient. They
rely on inheritance to define interfaces and obtain new functionality.

Adapter
It is a structural pattern that allows two objects with incompatible
interfaces to collaborate, through an intermediary with which they
communicate and interact.

Bridge
In this pattern, an abstraction is decoupled from its implementation, so it
can evolve independently.

7
Chapter 1 Introduction

Composite
It allows you to create objects with a tree-like structure and then work
with these structures as if they were individual objects. In this case, all the
elements of the structure use the same interface.

Decorator
This pattern allows you to add new features to an object (including this
object in a container that contains the new features) without changing the
behavior of objects of the same type.

Façade
It provides a simplified interface to a complex structure (such as a library
or set of classes).

Flyweight
It is a pattern that allows you to save RAM by having many objects share
common properties on the same object, instead of maintaining these
properties on every object.

Proxy
It is an object that acts as a simplified version of the original. A proxy
controls access to the original object, allowing it to perform some tasks
before or after accessing that object. This pattern is often used for Internet
connections, device file access, etc.

Behavioral Patterns
They are the most numerous, and they focus on communication between
objects and are responsible for managing algorithms, relationships, and
responsibilities between these objects.

8
Chapter 1 Introduction

Chain of Responsibility
It allows requests to be passed through a chain of handlers. Each of these
handlers can either process the request or pass it on to the next. In this
way, the transmitter and the final receiver are decoupled.

Command
It transforms a request into an object that encapsulates the action and
information you need to execute it.

Interpreter
It is a pattern that, given a language, defines a representation for its
grammar and the mechanism for evaluating it.

Iterator
It allows to cycle through the elements of a collection without exposing its
representation (list, stack, tree…).

Mediator
It restricts direct communications between objects and forces
communication through a single object, which acts as a mediator.

Memento
It allows you to save and restore an object to a previous state without
revealing the details of its implementation.

Observe
It allows establishing a subscription mechanism to notify different objects
of the events that occur in the object that they observe.

9
Chapter 1 Introduction

State
It allows an object to change its behavior when its internal state changes.

Strategy
It allows defining that, from a family of algorithms, we can select one of
them at execution time to perform a certain action.

Template Method
This pattern defines the skeleton of an algorithm in a superclass but allows
subclasses to override some methods without changing their structure.

Visitor
It allows algorithms to be separated from the objects with which they
operate.

SOLID Principles
These are five principles that will allow us to create reusable components,
easy to maintain, and with higher quality code.
SOLID is an acronym that comes from the first letter of the five
principles.

Single-Responsibility Principle (SRP)


A class should have one reason, and one reason only, to change. That is, a
class should only have one responsibility.

Open–Closed Principle (OCP)


We must be able to extend a class without changing its behavior. This is
achieved by abstraction.

10
Chapter 1 Introduction

Liskov Substitution Principle (LSP)


In a program, any class should be able to be replaced by one of its
subclasses without affecting its operation.

Interface Segregation Principle (ISP)


It is better to have different interfaces (protocols) that are specific to each
client than to have a general interface. Also, a client would not have to
implement methods that it does not use.

Dependency Inversion Principle (DIP)


High-level classes should not depend on low-level classes. Both should
depend on abstractions. Abstractions should not depend on details. The
details should depend on the abstractions. What is sought is to reduce
dependencies between modules and thus achieve less coupling between
classes.

 ow to Choose the Right


H
Architectural Pattern
We have just seen the advantages that our applications have a good
architecture offers us. But how do we choose the right architecture pattern
for our project?
In the first place, we have to know some information about our project
and the technology that we are going to use since we have seen that
some architecture patterns are better adapted to some projects and other
patterns to others.

11
Chapter 1 Introduction

Therefore, we must take into account, for example:

• The type of project

• The technologies used to develop it

• Support infrastructure (servers, clouds, databases…)

• User interface (usability, content, navigation…)

• Budget and development time

• Future scalability and the addition of new


functionalities

If we take into account everything seen so far, the choice of a good


architecture pattern (along with the use of design patterns and SOLID
principles) will allow us to have the following:

• A scalable application: A good architecture pattern


should allow us to add new features and even change
some of the technologies used, without having to
modify the entire application.

• Separation of interests: Each component should


be independent of the code point of view. That is, to
function correctly, a component should only be aware
of those around it and nothing else. This will allow
us, for example, to reuse these components or simply
change them for others.

• A code easy to maintain: Well-written, structured


code without repetition makes it easier to understand,
review, or modify. Also, any new developer joining the
project will require less time to get hold of.

12
Chapter 1 Introduction

• A testable code: The previous points result in the fact


that it is easier to test a code if the functionalities are
correctly separated than if they are not.

• A solid, stable, reliable, and durable code over time.

Most Used Architecture Patterns


From a generic point of view of software development, there are
numerous architecture patterns, but we will focus on the most used for the
development of iOS applications:

• Model–View–Controller (MVC)

• Model–View–Presenter (MVP)

• Model–View–ViewModel (MVVM)

• View–Interactor–Presenter–Entity–Router (VIPER)

• View–Interactor–Presenter (VIP)

We will start with the best-known model and the one that every
developer usually starts working with, the MVC. From here we will work on
models that derive from it, such as the MVP and the MVVM, to end up with
much more elaborate models of higher complexity, such as the VIPER and
the VIP.
After these architectural patterns, we will see, in a more summarized
way, some more patterns, perhaps not so used or known, but that can give
us a better perspective of how to structure an application. Examples of
these types of patterns are RIBs (developed by Uber) and Redux (based on
an initial idea of ​​Facebook for a one-way architecture).

13
Chapter 1 Introduction

In Search of a “Clean Architecture”


The “Clean Architecture” concept was introduced by Robert C. Martin
in 2012,2 and it is not an architecture, but a series of rules that, together
with the SOLID principles, will allow us to develop software with
responsibilities separate, robust, easy to understand, and testable.

Clean Architecture Layers


According to this philosophy, for an architecture to be considered “clean”
it must have at least the following three layers: Domain Layer, Presentation
Layer, and Data Layer (Figure 1-2).

2
https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-­
architecture.html

14
Chapter 1 Introduction

Figure 1-2. Scheme of the layer structure in Clean Architecture.


Dependency rule arrows show how the outermost layers depend on
the innermost ones and not the other way around

Domain Layer
It is the core of this architecture and contains the application logic and
business logic. In this layer we find the Use Cases or Interactors, the
Entities, and the Interfaces of the Repositories:

15
Chapter 1 Introduction

• Use Cases or interactors: They are in charge of


defining and implementing the business logic. They
control the flow of information to and from the Entities.
They can work with one or more entities and access
their methods.

• Entities: These are simple objects (which can be simple


data structures or can also contain methods) that
contain the business rules.

• Repository interfaces: They contain the definition


of the methods that will be implemented in the
Repositories. Repositories are responsible for obtaining
and passing data from databases, servers, etc.

This layer has no external dependencies, so it is easily testable (Use


Cases) and can be reused in other projects.

Presentation Layer
This layer contains all those elements that show information to the user or
that receive their interaction.
The Presentation layer also includes those components, such as
ViewModels or Presenters, that help prepare the data to be displayed on
the screen.
The ViewModels or Presenters are also in charge of executing the Use
Cases. The Presentation Layer only depends on the Domain Layer.

Data Layer
It contains the implementation classes of the Repositories and the data
sources such as databases, user preferences, or access to servers. In the
same way as the Presentation Layer, the Data Layer only depends on the
Domain Layer.

16
Chapter 1 Introduction

The Dependency Rule


For this type of architecture to work correctly, we must apply the so-­
called Dependency Rule. According to this rule, the inner layers must not
know the outer layers (i.e., no variable, method, etc., of an outer layer is
mentioned in a more inner layer).

Advantages of Applying a Clean Architecture


The application of a Clean Architecture in our projects will give us a series
of advantages (some of which we have already seen in the introduction to
Software Architecture):

• Testable: The fact that the business logic is isolated in


its layer, and that it does not depend on the rest of the
layers, makes it easily testable.

In addition, this same separation by layers allows them


to be tested separately and more easily locate any
possible error.

• Independent of frameworks: The code must be


independent of specific libraries.
In other words, we can change one library for another
without the need for major changes in the code and
without the internal layers stopping working because of
it. This is achieved by preventing our code from having
direct dependencies on these libraries.

• Independent of the user interface: The user interface


is the outermost layer and only displays the data
supplied by the presenter.

17
Chapter 1 Introduction

Therefore, we must be able to modify it without


affecting the most internal part, the business logic. In
other words, the user interface must adapt to changes
in business logic and not the other way around.

• Independent of data sources: In a similar way to


what was explained for the independence of the user
interface, we must be able to change the data sources
(local, external databases…) without affecting the
business logic, since it is these sources that fit the
business logic.

• Independent of external elements: The business logic


must be independent of everything that surrounds it,
which must allow us to change any part of the rest of
the system without affecting it.

 yToDos: A Simple App to


M
Test Architectures
To work with the different architectures that we have mentioned before
(MVC, MVP, MVVM, VIPER, and VIP), we are going to create a simple task
management application, which is, usually, one of the first applications
that a developer usually does.

App Screens
Our MyToDos app will allow us to work the navigation between different
screens (create lists, create tasks…); use a database to save, update,
or delete tasks; and, finally, manage user interactions on the different
screens.

18
Chapter 1 Introduction

Launch Screen
It is the screen that appears when loading the application (Figure 1-3).

Figure 1-3. Launch screen

Home Screen
This screen shows the lists we have created. If we haven’t created any list,
an “Empty State” will appear to tell us to create our first list.
For each created list, we will be able to see the icon that we have
associated with the list, the title of the list, and the number of tasks that
compose it (Figure 1-4).

19
Chapter 1 Introduction

Figure 1-4. Empty state on Home screen

The user can interact on this screen at three points:

• Using the Add List button, which will allow us to create


a new list

• Selecting one of the lists to access its content


(Figure 1-5)

20
Chapter 1 Introduction

Figure 1-5. Access tasks list on select cell

• Deleting lists by a swipe gesture on the list (Figure 1-6)

21
Chapter 1 Introduction

Figure 1-6. Delete list on swipe cell

Add List Screen


This screen is navigated through the Add List button on the Home screen.
Here, the user has to indicate the title that will be given to the list and
select an icon from those that are shown (Figure 1-7).
When you select the Add List button, the entered information is saved
in the database (Core Data) and you return to Home.
If the user wants to return to Home without creating any list, they
simply have to select the button with the return arrow located at the top
left of the screen.

22
Chapter 1 Introduction

Figure 1-7. Add List screen

Tasks List Screen


This screen is navigated by selecting one of the lists that appear in the
Home. If we do not have any task created, an “Empty State” will appear
indicating how to create a task (Figure 1-8).

23
Chapter 1 Introduction

Figure 1-8. Tasks List empty state

The user can interact on this screen at three points:

• Using the Add Task button, which will allow us to create


a new task (Figure 1-9).

24
Chapter 1 Introduction

Figure 1-9. Tasks List screen with an added task

• Selecting the circle to the right of each task will allow us


to mark it as done (Figure 1-10).

25
Chapter 1 Introduction

Figure 1-10. Task checked as done

• Deleting tasks using a swipe gesture in the list


(Figure 1-11).

26
Chapter 1 Introduction

Figure 1-11. Delete task

Any modification on this screen (change the status of a task or delete it)
is automatically saved in the database.
If the user wants to return to Home without creating any task, they
simply have to select the button with the return arrow located at the top
left of the screen.

Add Task Screen


This screen is navigated through the Add Task button on the Tasks List
screen and is displayed as a modal. Here, the user has to indicate the
title that will be given to the task and select an icon from those that are
displayed.
When you select the Add Task button, the entered information is saved
in the database (Core Data) and you are returned to the Tasks List screen.

27
Chapter 1 Introduction

If the user wants to return to the Tasks List screen without creating any
tasks, they simply have to drag the screen down (Figure 1-12).

Figure 1-12. Add Task screen

App Development
Before we start working with the different architectures in the next
chapters, let’s first see how to prepare the application for it.

Technologies Used
For the development of this application with each of the architectures,
Xcode 13.3 and Swift 5.6 have been used.
The database used is Apple’s own Core Data, and the views and
navigation between them have been developed directly with code, without
using .xib or .storyboard files.

28
Chapter 1 Introduction

How to Remove Storyboard Dependence


To develop the application (with the different architectures) without using
a storyboard, we have to do the following:

• First of all, we open Xcode and select the Create a new


Xcode project option (Figure 1-13).

Figure 1-13. Welcome to Xcode screen

• Next, we select the App template in iOS (Figure 1-14).

29
Chapter 1 Introduction

Figure 1-14. App template selection screen

• The next step is to indicate the name of the application


(Product Name), select the development team and
the organization identifier, and choose Storyboard as
the interface, Swift as the language, and Include Tests
(Figure 1-15).

30
Another random document with
no related content on Scribd:
“Do you think it’s a fair track?” inquired Miss Yale, anxiously, as they
came in sight of it. “It is an eight-lap track, you see, and of course a great
many girls only go around four times at first—girls get tired so absurdly
easy! Now I suppose men think nothing of making two miles at a time—it is
just play for them. Men are so strong—that is their greatest fascination, I
think,” she ran on enthusiastically. “Haven’t you seen foot-ball players after
a hard practice game start off and run two miles around the track, and seem
to think absolutely nothing of it?”
“Oh, that’s nothing,” said Newbold, unwarily and warmly. “Fellows are
so different from girls, you know. A girl cries when she’s tired, doesn’t she?
Well, a man just keeps going, you know, and doesn’t let it make any
difference to him.”
“I am so glad to hear that, Mr. Newbold,” said Miss Yale, with prompt
and suspicious sympathy, and a sudden firmness of tone, “because I wanted
dreadfully to ask you to try the track, but hated to do so, for I knew you were
tired—at least you look so. But since you just keep going, and it doesn’t
make any difference to you, why I would be so awfully obliged if you would
run around three or four times. I want to see just how you hold your head
and arms. I don’t believe we do it in the best way, you know.”
It was a rare and pleasingly curious sight that Miss Yale and Miss Thayer
and a great many other young women assembled near the track, apparently
by a strange coincidence, looked upon. It is not often that one has the chance
of seeing an immaculately dressed youth, with flushed and desperate
countenance, tear madly around an eight-lap track in the presence of a
number of flatteringly attentive young women. It occurred to Newbold as he
dashed around and around that it would be far preferable to keep going until
he fainted away or dropped dead, than to stop and encounter the remarks and
glances of those young women. They would at least feel sorry for him in that
case, he thought, gloomily. But even that modest and simple desire was not
granted him. As he started on the fifth lap he heard Miss Yale call to him to
stop. He had a wild inclination to pay no attention to her, but to keep going
on and on, but as he got nearer he saw her step out toward him and put up a
warning hand.
“Thank you so much,” she said, warmly. “I think we have all had a lesson
in running which we shall not forget soon. I hope you are not tired?” she
went on, anxiously.
Newbold said, “Oh, no!” but he felt very tired indeed. His feet ached
horribly and his head felt hot and dizzy, and there were queer, sharp pains
shooting through his body which made him think forebodingly of
pneumonia.
“The surprise is ready—Miss Atterbury is going to have the crew out for
your especial benefit!” went on Miss Yale, triumphantly. “Don’t you feel
complimented? And you are to pull Miss Thayer and myself about while
they go through a little practice for you. Not much, you know, but just
enough to show you the stroke and speed we get. The boat is a beauty—but
then, of course, you know so much more about it than we do! I imagine from
your article that you must pull an oar capitally. Miss Thayer says a cat-boat
is your especial hobby, though.”
“Did Miss Thayer say that?” began Newbold, hotly. “Beastly things, I
think—hate ’em!”
Miss Yale smiled incredulously and brightly at him.
“How modest you are!” she said, admiringly. “Ah! there is Miss
Atterbury!”
Newbold saw some one waving frantically at them.
“Come on!” exclaimed Miss Yale; “we want to see them start off—that’s
the best part.”
Newbold never remembered afterward how he got across the intervening
space, or how he got into a boat with the two young women. The first thing
he heard was Miss Atterbury asking him anxiously how he liked the new
sliding-seats, and what he thought of the proportions of the boat, and about
outriggers in general, and where he thought they could be built best and
cheapest. Newbold felt about as capable of instructing her on such points as
of judging the pictures at a Salon exhibit, and he longed, with a longing born
of utter exhaustion and desperation, to get away. As he wearily pulled the
heavy, unwieldy boat about after the light practice-barge, which kept an
appalling distance ahead of him, he decided within himself that the physical
development of women had been carried to an absurd and alarming extent,
and that men simply were not in it with them when it came to endurance and
enthusiasm, and that he had made the mistake of his life when he wrote that
article on athletics in girls’ colleges, and that his chief might talk until he
was blue in the face before he would ever consent again to write about
anything of which he knew so little.
They were very disappointed when he told them firmly that he could not
stay to dinner or to the concert, but that he had a pressing engagement that
would take him back to the city. And they said that there were still the
Swedish gymnastics and basket-ball and pole-vaulting to see, and that they
were afraid he had not enjoyed himself or he would have got rid of that
engagement in some way; but he assured them impressively that he had
never spent a more instructive or peculiarly interesting afternoon in his life.
Miss Thayer took him back to the station in her trap, and remarked on
how much shorter the way seemed with a good horse; and when she bade
him good-by she told him that she would be looking out for another article in
his paper, and that she would be much disappointed if his visit had not
inspired him to write something. To which Newbold replied that that was his
pressing engagement—he was going back to the city to write another article
on athletics in girls’ colleges, and that he thought it would be different and
better than the former one, but that he would not put his initials to it this
time.
THE COLLEGE BEAUTY

I T was a sort of farewell party, and the young woman who was going away
and who was the object of so much solicitude and tender concern was
sitting, enshrined as it were, on a divan covered with a Navahoe Indian
blanket and surrounded by innumerable cushions, while the rest hung about
her or took up precarious attitudes on the table in dangerous proximity to the
student lamps, or settled themselves in steamer-chairs, or sat upon the tiger-
skin on the floor. That is, the American girls did; Kan Ato, the pretty
Japanese who had come arrayed in a gorgeous new kimono—dull blue
embroidered splendidly in silver—sat upright and very stiffly in the window-
seat with the dark red of the curtains showing off her jet black hair and her
gown wonderfully well; while the tall Scotch girl, a cousin of the guest of
honor, had trusted her generous proportions to the only large, comfortable
American chair in the room.
There was a great deal of noise and confusion and questioning, and Miss
Lavington, as she leaned back against her cushions, half wished that after all
the doctor had not let her come. She had been very ill—a short, sharp attack
of typhoid—and although she had enjoyed tremendously the wine jelly, and
the violets, and the hushed, anxious tones of her friends as they inquired
after her at the infirmary, and the many remarks about her good qualities and
how clever she was in Conic Sections—“just as if she were really dead,” as
she said—still she felt rather too weak properly to appreciate her friends’
enthusiastic sympathy at such close range. And then the thought of going
away—and so far away—had made her feel blue and dispirited.
She was a very pretty English girl, whose father—a colonel in an Indian
regiment—had sent her to America in the care of a sister of his who had
moved to “the States;” and so it had come about that, instead of being a
Girton or Newnham girl, she had matriculated at this American college. And
now her father had written decisively for her to come out and join him in
India, and her college friendships and ties were all to be broken. He had been
writing about it for some time, and her illness had finally precipitated the
affair. She had only waited until she grew strong enough to start, and the
following day had been decided upon. The long sea-voyage would be the
very thing for her, the doctor had thought.
She was trying to explain to the interested young women just what route
she would take, and was rapidly filling their souls with envy at the familiar
mention of Brindisi and Cairo and Aden, when there was a knock and a
quick opening of the door and a girl came into the room. She was a very
beautiful young woman, and when she sat down on the divan beside Miss
Lavington she seemed suddenly to absorb all the attention and interest, and
to become in some magical way the guest of honor and centre of attraction.
She met with a very enthusiastic reception, for she had that afternoon gained
the tennis championship for her class—she was a senior—and had not yet
changed her white flannel suit with scarlet sumach leaves worked on it, and
as she dragged off her soft cap, one could see that her hair still lay in damp
curls upon her forehead.
After she had entered the room one would have realized that they had
really been waiting for her. Her mere presence seemed to make a difference.
It was this magnetic quality which rendered her so irresistible and all adverse
criticism of her so absurd. People might differ as to her beauty—there were
some indeed, who said that she was too large, or that her eyes were not very
expressive, or that her mouth was too small, but they all fell under her
influence in some remarkable way, and were very much flattered when she
asked them to drive with her, and never failed to point her out to their friends
as “the College Beauty, you know;” and even those who honestly wondered
how she ever got through her examinations were forced to admit that she had
a great deal of natural talent, which she did not always care to exercise. She
was a fine tennis player too, using either hand equally well, and when the
Tennis Association got itself into debt and she saved the situation by
beguiling, in some inexplicable way, the famous musical organization of a
certain university into giving a concert for its benefit, her popularity reached
its climax. To the less sought-after girls, her composure and ease of manner
while surrounded by an admiring circle of college men was nothing short of
marvellous, and the recklessly generous disposal which she made of these
youths to her less attractive friends seemed to betoken a social prodigality
little short of madness.
Miss Lavington looked at her imploringly.
“Make them keep quiet, won’t you?” she said. The Beauty looked around
her—“Are you trying to make her ill again, so she can’t go?” she asked.
Her words had the desired effect, and the girl who had been twanging
abstractedly at a banjeurine put it down.
“She oughtn’t to leave!” she declared, plaintively. “It’s a shame! Here we
are, just beginning the semestre, and she’s only half through her college
course anyway, and just because her father wants her she has to give up
everything and go.”
“Yes, and you know she’ll be sure to have jungle-fever or get bitten by a
cobra or something, and die,” suggested someone cheerfully, if a trifle
vaguely.
The girl lying on the tiger-skin looked up.
“I know why her father wants her,” she began calmly. “There is an officer
—young, handsome, well born, a fine place in Surrey or Devon or Kent,
been in the family for generations, old uncle, no children—just the thing for
her. Her father will take her up to some place in the Himalayas to spend the
summer, and he will arrange for the handsome, young, etc., officer to be
there, and next fall we will receive the cards. It sounds just like one of
Kipling’s stories, doesn’t it?”
They were all laughing by the time she had finished, but The Beauty,
looking at the girl beside her, suddenly stopped smiling. There was a
conscious flush on Miss Lavington’s face which set her to thinking, and then
she glanced over to the big Scotch girl and waited an instant.
“Tell us all about it,” she said finally to Miss Lavington. The girl looked
up quickly and then dropped her eyes again.
“There isn’t much to tell,” she began. The others were listening now.
Even Kan Ato, smiling in her pensive, oriental way, leaned far forward so as
not to lose a word.
“He isn’t rich and he hasn’t any place in Surrey—or anywhere else that I
know of, except perhaps in India,” she went on. “But he is young and
handsome. We used to know each other when we were children—he is a sort
of cousin—but I haven’t seen him for years. We used to be very much in
love with each other.” She smiled. “My father writes me that he says he is
still in love with me, and so—perhaps we are to be married.”
“I knew it,” sighed the girl on the tiger-rug, in a satisfied sort of way.
The Beauty looked at the English girl curiously. “And you haven’t seen
him for years? and yet you think of marrying him! How do you know you
will love him now?—you are both changed—you may be two totally
different people from the children who fell in love.” She had spoken
vehemently and quickly, and Miss Lavington gazed at her with languid
surprise.
“You are not in love with him yourself?” she said, smilingly.
The girl made a quick, impatient gesture.
“I am speaking seriously,” she said. “You are several years younger than I
am, and you don’t know what you are doing. Don’t let your father—don’t let
anyone—persuade you to bind yourself to a man you don’t know, whose life
has been so vitally different from your own as to render the possibility of
sympathy between you very slight.”
Miss Lavington looked at her rather coldly.
“You are interesting yourself unnecessarily,” she said; “I loved him not so
many years ago—it cannot be possible that so short a time would change us
completely.”
The Beauty leaned her head back with sudden wearied look on her face.
“A few years at our time of life makes all the difference in the world,” she
said, earnestly. “What pleased and interested and fascinated us at eighteen
might very possibly disappoint and disgust us at twenty or twenty-two. I do
not mean to preach,” she said, smiling deprecatingly and turning to the rest,
“but you know as well as I what an influence this college life has on us, and
how hard it is to go back to former conditions. If we get stronger here we
also get less adaptable. We are all affected by the earnestness and the culture
and advancement of the life we lead here for four years, whether we will or
no, and it is very hard to go back!”
They were all looking at her in amazement. The Beauty was not much
given to that sort of thing. She stopped abruptly as if herself aware of the
sensation she was creating, and laughed rather constrainedly.
“Don’t marry your handsome officer unless you are in love with him!”
she said insistingly still to the girl beside her. “Don’t mistake the childish
affection you felt for him for something deeper. You have your whole life
before you—don’t spoil it by precipitation or a false generosity or a reckless
passion!” There was an anxious, troubled look in her eyes.
The girl still stretched out on the tiger-skin glanced up again at The
Beauty. “I seem to have started a subject in which you are deeply
interested,” she said gayly to her. “And one in which you have had enormous
experience too. Do you know you have an almost uncanny way of
fascinating every man who comes near you. It’s a sure thing. None of the
rest of us have a chance. I believe you could marry half a dozen or so at any
time that you would take the trouble to say ‘yes’!”
The girl addressed looked openly amused—“Please take a few off your
list,” she said. But the other refused to notice her remark and ran on in her
light way.
“And they are all so nice too—it is really hard to choose, but I think on
the whole I prefer a certain young man who shall be nameless. Now, would
you call his devotion to yourself ‘mad precipitation or a false generosity or a
reckless passion?’ ” She moved herself lazily over the yellow skin until her
head rested against the girl’s knee.
“And he is such a nice, eligible youth too. I hope you are not going to
spoil his life by refusing him. Only think how lovely it would be to have
one’s father-in-law representing the majesty of these United States at an
Emperor’s court,” she went on, turning gayly to the others. “And he is so
handsome and clever! He will be representing Uncle Sam himself some day,
and she will be reading up the rules of court etiquette and receiving
invitations from the Lord Chamberlain to dine with the Queen, and fuming
because the Grand Duchess of something or other has the right to walk in to
dinner before her.” She was not noticing the girl’s significant silence. “Of
course he is just the man for you—you wouldn’t make any but a brilliant
match, you know, with your beauty and society manner. But just for the
present—well, next winter you will début, and you will be much talked
about, and the youth will not be with his father at the European capital, but
will be very much en évidence here, and then—after Easter we shall get your
cards!”
She twisted her head around, smiling, so as to get a look at the girl’s face
above her. It wore so grave and hopeless an expression that she gave a little
cry.
“Forgive me,” she said, confusedly, “but you do love him, don’t you?”
The Beauty turned her eyes away and shook herself slightly, as if
awakening from a dream.
“As confession seems to be the order of the hour,” she said in a dull tone,
and smiling peculiarly, “I don’t mind owning that I do love him very much.”
She got up abruptly and moved toward the door amid a chorus of
protests, but she would not stay. At the threshold she turned to Miss
Lavington.
“Send your things down by the coach,” she said. “If you will let me I will
be glad to drive you to the station myself to-morrow.”

When she got to her own study she found a letter thrust under the door
with the familiar number of her room scrawled upon it in pencil. She picked
it up, and as she looked at the address an expression of profound dislike and
weariness came into her face. She opened the door slowly and put the letter
down upon her desk, looking at it thoughtfully for a few moments. The
handwriting was irresolute and boyish. She shivered slightly as she took the
letter up with sudden resolution and tore it open. As she sat there and read it
a look of hatred and disgust and utter hopelessness, strangely at variance
with her usual brilliant expression, settled harshly upon her lovely, young
face.
“My Dearest Wife,” it ran, “Forgive me! but this is about the only
luxury I indulge in!—calling you in my letters what I dare not call you as yet
before the world.
“I am in a retrospective mood to-night, and feel like writing all sorts of
things which I am afraid you won’t much like. Do you know I think that
college is doing you harm! Don’t get angry at this, but sometimes I’m afraid
you have repented of our boy and girl runaway match; but God knows I
haven’t, and I’m glad I didn’t go to college but came out West and went to
work for us both. I haven’t succeeded very brilliantly and may be the life has
roughened me a bit, but I guess you can have the best there is out here, and I
am still as devoted to you as in those old days of the summer before you
went to that confounded (excuse me!) college, when you were just eighteen
and I barely twenty-one. How interminably long four years seemed to wait
then! But it was a case of getting married secretly and of waiting, or of not
getting you at all. Sometimes I can hardly stand it, and I’d come back now
and take you away, if I wasn’t so afraid of that blessed old father of yours—
but I’m just as big a coward as I was three years ago, when I couldn’t screw
up courage enough to go to him and tell him that he’d have to relinquish his
pet scheme of sending his daughter to college, for she belonged to me.
Whew! what a scene we’d have had! It was best to wait, I suppose.
“After all, only a year and then I can claim you! Have you changed any?
I’m afraid you’re way ahead of me now. I always had an uncomfortable
suspicion that you were very much my superior, and I have half fancied that
perhaps you only loved me because I was so madly—so passionately in love
with you. Did I over-persuade you? have you ceased to love me? Sometimes
I get half sick with fear. You are all I have! But after all I feel safe enough—
I know you too well not to know that you will never break your promise—
even one you hate. But you know I’ll never hold you to that marriage—
though it was all valid enough—if you don’t want to be held. I can simply
blow my good-for-nothing brains out.
“I won’t write any more to-night. There is so much swearing and noise
down in the street that I can hardly think; besides I don’t feel just like it, and
lately your letters have only irritated me. But I won’t complain, for I know
how generously you have acted and what brilliant prospects you have given
up for my precious self!
“Devotedly yours and only yours,
“G. G. B.”
A TELEPHONED TELEGRAM

W HEN Miss Eva Hungerford married Stanhope there was one young
lady intensely glad of it, although it was whispered that there were also
two or three who were quite the contrary. But Mrs. Renford Phillips—
once Miss Violet Featherstone—had particular reasons for rejoicing, and she
wrote a long letter to Miss Hungerford when she heard of the engagement,
and said that she hoped “by-gones would be by-gones now, and that she was
sure her friend would be a broader-minded and more perfect woman, if that
were possible, now that she was going to have the additional experience of
getting married.”
Miss Hungerford wrote her a most cordial reply, and the two girls, for
several years slightly estranged, became again the friends they had been
during the first three years of their college life.
The blow had fallen very suddenly, and Miss Hungerford had found it
hard to forgive what she called, in her heart, her friend’s tacit deceit and
culpable silence. But, as she wrote in her reply to Mrs. Phillips’s letter, her
opinions had undergone a decided change, and she felt that perhaps she had
been a little hard on her friend and had not understood her feelings and the
pressure brought to bear upon her, and she acknowledged that circumstances
might materially alter one’s views and actions. And Miss Featherstone, who
had been the most talked about girl in college during the last semestre of her
junior year, and who had suffered acutely under Miss Hungerford’s
indifferently concealed displeasure and surprise at her conduct, replied that
now she could be truly happy in her husband and her home, and insisted that
Mr. and Mrs. Stanhope should visit her in the Berkshire Hills that summer.
This they did, and though, of course, each thought her husband much the
handsomer and more distinguished-looking, still they were very affectionate
toward each other, and planned to be at Cowes together the next summer for
the yachting.
As has been said, their estrangement happened very suddenly and came
about by an unfortunate occurrence one morning in the office of the college.
Anyone who has never had the privilege of being in that office on a
Monday morning, just after chapel, can have but a faint idea of
pandemonium. The whole seven hundred students seem to be revolving
about. There are the young women standing around, waiting to take the next
train into Boston, not having been able to go on the early express because
they had foolishly forgotten to get a leave of absence on the Saturday
previous, and who are furtively trying not to see their friends who are not
going on at all, so as to keep from having to attend to their commissions; and
there is the girl who is telephoning for roses to wear at the concert that night,
and those who are booking boats and tennis courts, and others reading
bulletins; and when there is an extra commotion and the crowd is forced
back a little to let the cords be pulled up around the desk so as to clear a
space; and when the carrier comes in and tumbles the big mail-bags into the
middle of it with one hand and unlocks them at apparently the same instant
with the other; and when about ten young women fall upon the bags and
rend their contents from them, and begin to assort and number and tie up the
letters, all the time besieged by their excluded friends to give them their mail
on the spot as they are going away, the noise and excitement reach a climax.
But it is all very pleasant and enlivening except the telephone bell, which
rings constantly and is wearing on the nerves. It rings not only for all
telephone messages but for all telegrams, for the college, being a mile or so
from the telegraph station, everything is simply telephoned up to save
delays, and that a long and continuous procession of small messenger boys
may not be forever circulating between the college and the station.
It was this unfortunate custom of telephoning telegrams, unknown of
course to the majority of outsiders, that precipitated the affair. On that
particular Monday morning, when the confusion in the office was at its
worst, the telephone bell suddenly rang unusually loudly and long, and the
nervous Freshman on duty jumped toward it with a warning motion to the
rest to keep quiet.
“Hush! it’s a telegram,” she said in a moment, and instantly there was
silence, for a telegram is always dreaded where there are so many to whom it
could bear ill news. She reached for a pad of paper and a pencil to take it
down. From the other end came “Important. Repeat slowly as I deliver it.”
The nervous Freshman said “All right,” and braced herself against the
support to write.
“To Miss Violet Featherstone.” The docile Freshman repeated it and then
said “Wait!” and looked around.
“If Miss Featherstone is here,” she remarked, “she can come to the
telephone;” but someone volunteered the information that Miss Featherstone
had left by the early train for Boston, and the telephoning proceeded.
“My darling—” the Freshman gasped a little and then repeated slowly
“My darling.” There was some suppressed commotion for an instant among
the crowd around the doors, and the two at the telephone went at it again.
“I have not heard from you for three days.”
“I have not heard from you for three days,” mumbled the Freshman.
“What is the matter? Renford Phillips.”
“What is the matter? Renford Phillips.”

When Miss Featherstone reached the college that afternoon she thought
she detected a suppressed excitement about the whole place, though she felt
rather too tired to think much about it, but when she got to her room she
found a telephone message for her which made her sink weakly into a chair.
An appalling vision of the consequences rose before her. She tried to
think connectedly, but the effort was too much. Her only thought was of the
effect it would have on her friend Eva Hungerford. She would go to her
immediately and find out how much she knew.
As she went along the corridors more than one acquaintance smiled
knowingly at her, but she only hurried on. When she reached Miss
Hungerford’s rooms, she found that young lady looking dejectedly out of the
windows. Her melancholy turned to stony haughtiness, however, when Miss
Featherstone approached her tremblingly.
“Yes, the whole college knew of it,” she assured her. “The message had
been telephoned up when the office was crowded, and by this time everyone
was aware of what her best friend had not known.”
Miss Featherstone rebelled a little under Miss Hungerford’s chilling
glance and attempted to explain, but her friend was very sad and firm, and
said she did not see how any explanation could do away with the fact that
Violet Featherstone had broken the solemn vow they had made together
never to marry, but to devote themselves to serious study as a life-work. But
when Miss Featherstone quite broke down under her friend’s disapprobation,
Miss Hungerford relented a little and asked her if she were really so fond of
Renford Phillips, and if she thought life with him in Morristown would
compensate her for the loss of Oxford and the Bodleian. Miss Featherstone
cried a little at that, and said she thought it would, and that she had started a
hundred times to tell her dearest friend about her engagement, but she knew
how she thought about such things, and how she would lose her respect for
allowing anything to interfere with their plans for mental advancement. And
Miss Hungerford only sighed and wrote that night to her mother that another
of her illusions had been dispelled, but that she was firmer than ever in her
determination to make something of herself.
Miss Featherstone did not return for her degree, but had a pretty church
wedding that summer at Stockbridge, and Miss Hungerford sent her a very
handsome wedding gift, but refused to be present at the marriage. They did
not write to each other much the next year, and Miss Hungerford worked so
hard that the Faculty had to interfere, and when she left college with a B. S.
degree, smiling sadly and saying that she would be a bachelor as well as an
old maid, everybody remarked what a superior girl she was to her friend
Violet Featherstone.
“MISS ROSE”

S HE was always called that, and there were very few of the seven hundred
students who really knew or cared whether it was her little name or her
family name. The uncertainty about it seemed particularly appropriate
someway—her whole personality was vague. That is at the beginning; later
——
For the first month she passed comparatively unnoticed. In the wild
confusion of setting up household gods and arranging schedules, hopeless as
Chinese puzzles, of finding out where the Greek instructors can see you
professionally, and when the art school is open, and why you cannot take
books from the library, and when the elevator runs, anyone less remarkable-
looking than an American Indian or the Queen of the Sandwich Islands is apt
to be overlooked. But after the preliminary scuffle is over and there is a lull
in the storm, and one begins to remember vaguely having seen that dress or
face before somewhere, and when one no longer turns up at the history or art
rooms instead of the chemical laboratories, and when one ceases to take the
assistant professor of physics for the girl who sat next to you in the
trigonometry recitation—then the individual comes in for her share of
attention.
“Miss Rose” possibly got more than her share. Curious young women
soon began to nudge each other, and ask in whispers who she was. And just
at first there were covert smiles and a little cruelly good-natured joking, and
the inevitable feeble punning on her name and withered looks. There were
some who said she could not be more than forty-five, but they were in the
minority, and even the more generously inclined could not deny that her face
was very old and wrinkled and tired-looking, and that her hair was fast
getting gray around the temples, though her eyes still retained a brilliancy
quite feverish, and an eager, unsatisfied sort of look that struck some of the
more imaginative as pathetic. As a freshman she seemed indeed to be
hopelessly out of place—though not so much so, perhaps, as the little
Chicago beauty who was so much more interested in her gowns and looks
than in her work, that at the beginning of her second semestre she went
home with an attack of pneumonia, brought on by having been left out in the
cold after an examination in conic sections.
That type, however, is not uncommon, while “Miss Rose” was especially
puzzling. They could not quite understand her, and there were even some
among the august body of ridiculous freshmen who somewhat resented her
entrance into their ranks, and wondered rather discontentedly why she did
not join the great body of “T-specs” to which she so evidently belonged.
But it was characteristic of this woman that she preferred to begin at the
beginning and work her way up—to take the regular systematic grind and
discipline of the freshman’s lot—to matriculating in an elective course where
she could get through easily enough if she were so inclined. She saw no
incongruity in her position; she rarely seemed to notice the difference
between herself and the younger, quicker intellects around her, and she
worked with an enthusiasm and persistence that put most of the young
women to shame. That she had taught was evident—in what little out-of-the-
way Western town, or sleepy Southern one, no one knew; but sometimes
there were amusing little scenes between herself and the professor, when the
old habit of school-room tyranny which she had once exercised herself was
strong upon her, and she lapsed unconsciously into the didactic manner of
her former life. And sometimes she became discouraged when the long lack
of strict mental discipline irked her, and when she saw in a glimpse how far
she was behind the girl of nineteen beside her, and how hopeless was the
struggle she was making against youth and training. There were moments
when she realized that she had begun too late, that the time she had lost was
lost irretrievably. But the reaction would quickly come and she would work
away with renewed energy, and they were very patient with her and would
lend her a helping hand where a younger student would have been let most
severely alone, to sink or swim after the approved method.
But if her mathematics and chemistry and Tacitus left much to be desired,
there was one field in which she shone resplendently. “No one could touch
her”—as one young woman slangly but enthusiastically remarked—“when it
came to the Bible.” There she was in her glory, and her vast knowledge of
the wars of Jeroboam and Rehoboam, and her appalling familiarity with
Shamgar and the prophets, and the meaning of the Urim and Thummim, and
other such things, was the envy and despair of the younger and less
biblically inclined. And if at times she was a trifle too prolix and had to be
stopped in her flow of information, there was very genuine regret on the part
of the less well informed.
And in time she came to make a great many friends. Her peculiar ways no
longer struck them as comical, and if anyone had dared make reference to
the plainness of her gowns or the strict economies she practised to get
through, that person would have very soon discovered her mistake; and they
pretended not to know that she would not join any of the societies because of
the dues, and that she did her own laundry on Monday afternoons. Indeed,
she was so kindly disposed and so cheerful and helpful, and seemed so
interested in all the class projects and even in the sports, at which of course
she could only look on, that little by little she came to be a great favorite,
and the one to whom the rest naturally turned when there was any hitch or
especial need for advice. And then, of course, as she was not to be thought of
in the light of a possible candidate for president or vice-president or captain
of the crew, or any of the other desirable high-places, those misguided young
women who did have such literary, social, or athletic aspirations would go to
her and confide their hopes and fears, and in some strange way they would
all feel very much more comfortable and happy in their minds after such
confessions. And so she got to be a sort of class institution in a very short
while, and the captains of different stylish but rather un-nautical freshman
crews vied with each other in invitations to “come over the lake” with them,
and the president of the Tennis Association sent her a special and entirely
superfluous invitation to the spring tournament on the club’s finest paper,
and the senior editor of the college magazine, whose sister was a freshman,
was made to ask her for a short article on the “Study of the Bible,” and at the
concerts and receptions many young women, kindly and socially disposed,
would introduce her to their brothers and other male relations who had been
enticed out, before taking them on to see the lake, or a certain famous walk,
or the Art Building, or the Gymnasium.

It was about the middle of the winter semestre that it happened, and of
course it was Clara Arnold who knew about it first. Miss Arnold had liked
“Miss Rose” from the beginning. She had taken a fancy to the hard-working
woman, who had returned it with wondering admiration for the handsome,
clever girl. And so Miss Arnold got into the habit of stopping for her
occasionally to walk or drive, and it was when she went for her to go on one
of those expeditions, that she discovered the trouble. She found “Miss Rose”
sitting before her desk with a crumpled newspaper in her hand, and a dazed,
hopeless expression on her face which cut the girl to the heart. Her things
were scattered about the room, on the bed and chairs, an open trunk half-
filled stood in one corner. Miss Arnold stared around in amazement.
“The bank’s broken,” said “Miss Rose” simply, in answer to her
questioning glance, and pointed dully to the paper. “I might have known that
little bank couldn’t hold out when so many big ones have gone under this
year,” she went on, half speaking to herself.
Miss Arnold picked up the paper and read an article on the first page
marked around with a blue pencil. She did not understand the technicalities,
but she made out that the “City Bank” of a small town in Idaho had been
forced to close, and that depositors would not get more than five or ten cents
on the dollar.
“Every cent I’ve saved up was in that bank!” The woman turned herself
slowly in her chair and laid her face down on the desk with her arms above
her head. She spoke in muffled tones into which a strange bitterness had
crept.
“I’ve worked all my life—ever since I was twenty—to get enough money
to come to college on. I had barely enough to stay here at all—and now—”
she stopped suddenly, breathing hard. “I haven’t been here a year yet,” she
broke out at last.
“Well, I’ll have to go back to teaching. Great heavens! I thought I’d
finished with that!”
Miss Arnold seated herself on a clear corner of the bed.
“Look here, ‘Miss Rose,’ ” she said, excitedly, “of course you aren’t
going to stop college now, when you’re doing so well and—and we all like
you so much and—and you’re just beginning your course.” She stumbled on
—“Has everything gone?—can’t you do something?”
“Miss Rose” looked up slowly—“Everything,” she said grimly, and then,
with the pathetically resigned air of one who has been used to misfortunes
and has learned to accept them quietly, “I’ve worked all my life, I suppose I
can go at it again.” She looked around her. “I’ll be gone this time to-morrow,
and then I won’t feel so badly;”—she put her head down on the desk again.
Miss Arnold looked thoughtfully at her for a few minutes and then, with a
sudden movement, she got up and went out, closing the door softly behind
her.
It was about nine o’clock that evening and “Miss Rose” had almost
finished packing. She was feeling particularly disheartened and was taking
the books from the cases one by one in a very mournful way, when she heard
footsteps and a subdued but very excited whispering outside her door. She
got up languidly and threaded her way among the books and cushions and
odd articles of clothing heaped up on the floor. As she opened the door, the
light from her student-lamp fell upon the very red face of a freshman
propelled apparently into the room by the two or three others behind her,
who seemed to have a wild desire to efface themselves entirely.
“Miss Rose,” gasped the blushing freshman in the van, “here—here is a
letter for you. We’ve just had a class meeting—” she looked nervously at the
others who were edging away.
There was an indistinct chorus from them which sounded like “hope
you’ll accept,” and then they retreated with as much dignity as possible, but
in great haste.
“Miss Rose” opened the letter and gave a little cry as a check for a good
round sum drawn on the class treasurer fell to the floor. And then she sat
weakly down on the bed and cried a little from pure happiness as she read it
all over.
“The class of ’9—have just heard of ‘Miss Rose’s’ financial
embarrassment occasioned by the failure of the —— City Bank, and being
most unwilling to lose so valuable and appreciated a member, beg that she
will accept the enclosed and continue with the class until the end of the
year.”
A SHORT STUDY IN EVOLUTION

A COLLEGE for women is generally looked upon by the outside world


and the visiting preachers as a haven of rest, a sort of oasis in the desert
of life, a Paradise with a large and flourishing Tree of Knowledge of
which one is commanded to eat, and where one is happily ignorant of the
“struggle for life,” and the woes and evils of the world.
Such views have been so often expressed and inculcated that it appears a
little ungracious and stubborn to insist that the bishop who comes out and
delivers a sermon once a year, or the brilliant young graduate from a
neighboring seminary—who is sent because the dean has been suddenly
called away and who is quaking with fear at the ordeal—cannot possibly
know all about a girl’s college life and its temptations and its trials and its
vanities.
When the heterogeneous mass of humanity which makes up a big college
is got together and in close relation for ten months at a time, there is bound
to be action and reaction. When New York society girls and missionaries’
daughters from India, and Boston Latin-school girls and native Japanese, and
Westerners and Georgians and Australians and “Teacher Specials,” and very
young preparatory-school girls, are all mixed up together, it inevitably
happens that there is some friction and many unexpected and interesting
results. One of these is that it not infrequently happens that a young woman
leaves college an entirely different person from the girl who took her
entrance examinations, and sometimes the change is for the better and
sometimes for the worse, or it may be unimportant and relate only to the way
she has got to wearing her hair, or the amount of extra money she considers
necessary. At any rate, a noticeable change of some sort always operates in a
girl during her four or five years’ stay at a college, and when she goes home
“for good” her friends will criticise her from their different points of view,
and will be sure to tell her whether she is improved or not.
When Miss Eva Hungerford returned for her senior year at college,
having been greatly disappointed in one of her friends, she determined to
make no new ones, but to work very hard and keep a great deal to herself.
She succeeded so well in her efforts that, after she had been there three
months, she became aware that she knew absolutely none of the new

Вам также может понравиться