Develop well-structured applications using tested techniques and patterns. When you start to develop an application, you not only have to think about the idea of the finished application, but also about how it will evolve as it is built. This book shows you how to plan for changes, scope creep, and for the possibility of other developers joining in.
Start by learning what architecture patterns for an application are. You’ll find out why it’s important for your applications to be based on these patterns and which ones are the most common. Then you’ll look at the MVC as one of the best known and used patterns. You’ll see how and when it can be implemented in your applications, as well as its advantages and disadvantages.
From there, you’ll discover the first evolution of the MVC model: the MVP, which introduces a new layer (Presenter) to better manage views. The next evolution after that is the MVVM, which introduces the ViewModel layer and its connection with the views through Data Binding. With those prominent patterns covered, you’ll read about VIPER and VIP, Architecture Patterns that seeks to make applications easily maintainable, modularized, and highly scalable. All of which are hallmarks of Clean Architecture. Architecture patterns have developed and evolved to give your applications solid foundations. Understanding these patterns, you will reduce the problems that may arise when modifying existing functions, adding new ones, or correcting errors that may arise in the development process.
What You'll Learn- Code cleanly with solid foundations
- Start your project ready to adapt and evolve as features and other developers are added
- Find and apply the right patterns for the best results
Who This Book Is ForDevelopers with some programming knowledge who want to learn different architecture patterns, those who already have more experience and are looking for a starting point on complex patterns such as VIPER or VIP, and beginner programmers
Author(s): Raúl Ferrer García
Edition: 1
Publisher: Apress
Year: 2023
Language: English
Pages: 415
City: Berkeley, CA
Tags: iOS; Xcode; Architecture Pattern; Design Patterns; Code; MVC; MVP; MVVM; VIPER; VIP
Table of Contents
About the Author
About the Technical Reviewer
Acknowledgments
Introduction
Chapter 1: Introduction
What Is Software Architecture?
Architecture Patterns
Why Do We Need an Architecture Pattern for Our Applications?
Design from High Level to Low Level
Design Patterns
Creational Patterns
Factory Method
Abstract Factory
Builder
Singleton
Prototype
Structural Patterns
Adapter
Bridge
Composite
Decorator
Façade
Flyweight
Proxy
Behavioral Patterns
Chain of Responsibility
Command
Interpreter
Iterator
Mediator
Memento
Observe
State
Strategy
Template Method
Visitor
SOLID Principles
Single-Responsibility Principle (SRP)
Open–Closed Principle (OCP)
Liskov Substitution Principle (LSP)
Interface Segregation Principle (ISP)
Dependency Inversion Principle (DIP)
How to Choose the Right Architectural Pattern
Most Used Architecture Patterns
In Search of a “Clean Architecture”
Clean Architecture Layers
Domain Layer
Presentation Layer
Data Layer
The Dependency Rule
Advantages of Applying a Clean Architecture
MyToDos: A Simple App to Test Architectures
App Screens
Launch Screen
Home Screen
Add List Screen
Tasks List Screen
Add Task Screen
App Development
Technologies Used
How to Remove Storyboard Dependence
Core Data Configuration
How to Create Database and Entities
Create CoreDataManager
Summary
Chapter 2: MVC: Model–View–Controller
What Is MVC?
A Little History
Apple Model–View–Controller
Components in MVC
Model
View
Controller
Advantages and Disadvantages of MVC
Advantages of the MVC Pattern
Disadvantages of the MVC Pattern
MVC Application
MVC Layers
Model
Core Data
Models
Services
Extensions
Constants
View
Controller
MyToDos Application Screens
Information Flow
Delegate Pattern
How to Implement Delegate Pattern
AppDelegate and SceneDelegate
Home Screen
HomeViewController
HomeView
Add List Screen
AddListViewController
AddListView
Tasks List Screen
TaskListViewController
TaskListView
Add Task Screen
AddTaskViewController
AddTaskView
Testing
How Should the Tests Be?
Let’s Create the First Test
Helper Classes
MVC-MyToDos Testing
TasksListServiceTest
Mocking Services
Controllers Testing
Views Testing
Summary
Chapter 3: MVP: Model–View–Presenter
What Is MVP?
A Little History
How It Works
Components in MVP
Model
View
Presenter
Advantages and Disadvantages of the MVP
Advantages
Disadvantages
MVP Application
MVP Layers
Model
Core Data
Models
Services
Extensions
Constants
View
Presenter
MyToDos Application Screens
AppDelegate and SceneDelegate
Home Screen
HomeController
HomeView
HomePresenter
Add List Screen
AddListViewController
AddListView
AddListPresenter
Tasks List Screen
TaskListViewController
TaskListView
TaskListPresenter
Add Task Screen
AddTaskViewController
AddTaskView
AddTaskPresenter
MVP-MyToDos Testing
AddListViewController
AddListView
AddListViewPresenter
Summary
Chapter 4: MVVM: Model–View–ViewModel
What Is MVVM?
A Little History
How It Works
Components in MVVM
Model
View
ViewModel
Data Binding
Advantages and Disadvantages of MVVM
Advantages
Disadvantages
MVVM Application
MVVM Layers
Model
Core Data
Models
Services
Extensions
Constants
View
ViewModel
MyToDos Data Binding
What Is RxSwift?
Observables and Observers
Installing RxSwift
Input/Output Approach
MyToDos Application Screens
AppDelegate and SceneDelegate
Home Screen
HomeViewController
HomeView
HomeViewModel
Add List Screen
AddListViewController
AddListView
AddListViewModel
Tasks List Screen
TaskListViewController
TaskListView
TasksListViewModel
Add Task Screen
AddTaskViewController
AddTaskView
AddTaskViewModel
MVVM-MyToDos Testing
RxTest Introduction
HomeViewModel Tests
EmptyState Test
Testing the Deletion of Lists
List Selection Testing
MVVM-C: Model–View–ViewModel–Coordinator
What Is a Coordinator?
Using MVVM-C in MyToDos
SceneDelegate
Home Screen
Add List Screen
Tasks List Screen
Add Task Screen
Summary
Chapter 5: VIPER: View–Interactor–Presenter–Entity–Router
What Is VIPER?
A Little History
How It Works
Components in VIPER
View
Interactor
Presenter
Entity
Router
Advantages and Disadvantages of VIPER
Advantages
Disadvantages
VIPER Application
Communication Between Components
Communication Between Presenter and View
Communication Between Presenter and Interactor
Communication Between Presenter and Router
VIPER Layers
Modules
Services
Common
Core Data
Components
Models
Extensions
Helpers
MyToDos Application Screens
AppDelegate and SceneDelegate
Home Module
Home Protocols
HomeRouter
HomeViewController
HomePresenter
HomeInteractor
Add List Module
AddListProtocols
AddListRouter
AddListViewController
AddListPresenter
AddListInteractor
Task List Module
TaskListProtocols
TaskListRouter
TaskListViewController
TaskListPresenter
TaskListInteractor
Add Task Module
AddTaskProtocols
AddTaskRouter
AddTaskViewController
AddTaskPresenter
AddTaskInteractor
VIPER-MyToDos Testing
HomePresenter
HomeInteractor
Summary
Chapter 6: VIP: View–Interactor–Presenter
What Is VIP?
A Little History
How It Works
Components in VIP
View (UIViewController)
Interactor
Presenter
Router
Worker/Service
Model
Configurator
Advantages and Disadvantages of VIP
Advantages
Disadvantages
VIP Layers
Scenes
Services/Workers
Common
Core Data
Components
Models
Extensions
Helpers
MyToDos Application Screens
AppDelegate and SceneDelegate
Home Scene
HomeConfigurator
HomeView
HomeViewController
HomeInteractor
HomePresenter
HomeModel
HomeRouter
AddList Scene
AddListConfigurator
AddListView
AddListViewController
AddListInteractor
AddListPresenter
AddListModel
AddListRouter
TaskList Scene
TaskListConfigurator
TaskListView
TaskListViewController
TaskListInteractor
TaskListPresenter
TaskListModel
TaskListRouter
AddTask Scene
AddTaskConfigurator
AddTaskView
AddTaskViewController
AddTaskInteractor
AddTaskPresenter
AddTaskModel
AddTaskRouter
VIP-MyToDos Testing
HomeViewControllerTest
HomeInteractorTest
HomePresenterTest
Summary
Chapter 7: Other Architecture Patterns
Introduction
RIBs: Router, Interactor, and Builder
A Little History
How It Works
Components
Router
Interactor
Builder
Component
Presenter
View
Advantages and Disadvantages
Advantages
Disadvantages
The Elm Architecture
A Little History
How It Works
Components
Model
View
Update
Runtime
Advantages and Disadvantages
Advantages
Disadvantages
Redux
A Little History
How It Works
Components
State
Store
Reducer
Action
View
Middleware
Advantages and Disadvantages
Advantages
Disadvantages
TCA: The Composable Architecture
A Little History
How It Works
Components
State
View
Action
Reducer
Environment (Effect)
Store
Advantages and Disadvantages
Advantages
Disadvantages
Summary
Chapter 8: Conclusion
The Importance of Clean Architecture
Moving Forward
Index