Reader small image

You're reading from  An iOS Developer's Guide to SwiftUI

Product typeBook
Published inMay 2024
Reading LevelBeginner
PublisherPackt
ISBN-139781801813624
Edition1st Edition
Languages
Right arrow
Author (1)
Michele Fadda
Michele Fadda
author image
Michele Fadda

Michele is currently working as a technical project and program manager at Eggon, an innovative startup in Padua, Italy, and as the director of FWLAB Limited, a UK App development studio. He specializes in skills such as Imperative Programming, Functional programming, Swift, Mobile Application Development. He started programming as a child with Assembly language and has worked for 20 years as a consultant using a variety of languages and technologies. He started developing for iOS with iOS on iOS v.3.0 in 2009. He has also developed many apps as a solo developer and has also participated in numerous projects.
Read more about Michele Fadda

Right arrow

App Architecture and SwiftUI Part II – the Theory

This chapter will proceed with an introduction to the interesting topic of modern application architecture in the context of SwiftUI. Bear in mind that what we discuss here in terms of preferred frameworks is specific to the iOS context. In other programming environments, other approaches such as Model-View-ViewModel (MVVM) may be perfectly valid. However, what we are really interested in is the rich field of “software architecture” itself, as a concept.

Due to the limited scope of this book, remember that this will be just an introduction to this interesting, vast, and complex topic.

We are going to introduce software architecture, with a focus on theory, and allow you to determine whether certain architecture is well designed.

In this chapter, we’re going to cover the following main topics.

  • Keeping it light enough
  • Architecture – what is it?
  • Conflict and the role of the architect...

Keeping it light enough

In this section, we will discuss the design part of software. We don’t take the view that you should design everything from the start, with a “grand plan” that encompasses everything. That approach is often called waterfall, or upfront architecture. However, I don’t subscribe that you should go completely free-range and start with no intentional initial design either.

Take, for example, starting a journey with just a map, a backpack with some spare light clothes, and enough money. It helps if you have a plan, research the country you want to visit first, and know at least a bit of the language. Also, you may have “rules” you want to follow in order to maximize some criteria, such as your gastronomic preferences, sunshine intake, and having abundant sunscreen oil in order to avoid sunburn.

When it comes to software architecture, the goal is not to begin with a completely blank slate. Instead, you aim to have the...

Conflict and the role of the architect

If you have disagreements, most of the time it is a matter of unmatched expectations, and this can cause conflict. Alternatively, it could arise simply because of different roles and views. Conflict naturally occurs in teams, and if the conflict is respectful, this normally leads to increased performance and creativity. Like in a loving couple, you can quarrel about some choices but love and respect each other on a deeper level. If someone thinks we should always be forced to be friendly with everyone, and all decisions should be unanimously made, then really bad things will start to happen. You will not always be able to be friendly; sometimes, you are going to be sad or tired. There is no need to force everyone to smile all the time.

Go and research the term Groupthink. Groupthink is a phenomenon occurring in cohesive groups, identified by psychologist Irving Janis. Groupthink is a tendency within strong leadership that leads to ignoring...

What good software architecture is and what it is not

When we speak about software architecture, we don’t have hard and fast “recipes” that you can regard as laws to be followed blindly and memorized to guide you in your journey. Instead, however, we have more guiding principles about architecture that allow us to judge the architecture (structure) of a system and help us determine whether this structure is appropriate or not. The first such principle is the prescriptive statement that that we can use to define as a sort of rule-zero of architecture –“form must follow function” or, even more simply, “form follows function.”

I borrowed this from Bauhaus architecture school. The Bauhaus school was founded in Germany in 1919 and literally means “building houses.” It advocated for simplicity and practicality in form. When it comes to application structure, we discovered this philosophical view of the world in computer...

Don’t be shy; ask an expert!

It is very difficult to say that a specific architecture design is “ideal” because, as with many things in engineering, everything here is a matter of compromise. You will never “get it absolutely right,” and some of the questions you will meet will likely be so hard that sometimes even PhDs and university professors would end up on different sides of the discussion. Be humble and ask for help if needed; don’t rely solely on yourself and the few people you are working with. If there is a friendly data scientist with a penchant for stats and thorny statistics in your company, sometimes they will be the only soul who can help you. The same holds for cybersecurity, or some exotic expert domain subject that your system deals with.

An external expert can bring a different view to your own and your team, and asking for expert help will decrease the risk of what you are trying to achieve, always.

If you are not so...

The origin of software patterns

A pattern is another concept I borrowed from “real” architecture of the house building variety. The term was invented by Cristopher Alexander in his book A Pattern Language and was adopted by software architecture more than 20 years later by the “Gang of Four,” the authors of the book Software Patterns: Elements of Reusable Software – Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. The ominously named Gang of Four (GoF) was a team of two Siemens and two IBM engineers who discovered that most object-oriented computer systems tend to be composed by some “reusable solutions” that are specific to a context and can be reused, substantially independent from the programming language. Read the GoF book and keep it for reference.

Using software design patterns appropriately is normally considered a “best practice” when designing an object-oriented software system. Beware that a lot...

Agency theory and bad architecture

The idea that a company employee (an “agent” in economic theory) might do something that does not benefit his employer (the “principal”) if the employee can operate without being held accountable (e.g. because the employee knows that his actions are “hidden”) is called “Agency Theory.” This is a well-known, respected and well-researched sociological theory on the performance of decision-makers in organizations.

If your CEO does not subscribe to this theory, ask them to please give back their bonus, because them getting a generous managerial performance bonus is grounded in this theory being correct.

Agency theory, in practice, is difficult to prove, as proving beyond any doubt that someone is behaving less than honestly is really hard. In legal terms, what matters is not the actual truth (that is subjective most of the time) but what you can successfully prove in court.

However, according...

Clean Architecture

In terms of “pre-made” ready meal-style architecture, some might claim to have been inspired by “Clean Architecture” or that they offer an implementation of it. That is extremely strange, suspicious even. I doubt they actually read and, what’s more, understood the book Clean Architecture by Robert Martin.

Sometimes, all these people do is implement at face value an architectural diagram that was given as an example in that book. You should stop asking for recipes and implementing them in a piecemeal fashion.

What Robert Martin really observes in his book, which we can consider a fundamental discovery, is that in “real architecture,” the one related to houses and buildings, we have blueprints that are easily recognizable in terms of the purpose of the buildings they depict. Architecture is about intent.

You can tell the different intentional functions of a building by examining its blueprint.

A cathedral...

TCA, The Composable Architecture

For completeness, I will mention one of the latest additions to the collection of third-party “architectures” for iOS and Apple development. TCA, The Composable Architecture is a framework implemented as a library developed by PointFree: https://www.pointfree.co.

Unfortunately, TCA is not fully open source nor fully explained by a textbook when it comes to its documentation, as the PointFree business model is based on a subscription model. Some information, however, is available publicly, in particular on GitHub: https://github.com/pointfreeco/swift-composable-architecture

TCA is conceptually based on Redux, a software pattern used in Javascript frontend development, normally used with React.

Redux and TCA are two state management frameworks used in software development to manage and centralize the state of an application, making it predictable and easier to understand. Redux was originally designed for React applications in the...

Summary

In this chapter, we tried to give you a glimpse on the main concepts that underline software architecture and a brief description of what software architecture work entails. As this is not just a job involving programming concepts, we took the liberty to look at the topic from some other angles besides that of strictly computer science, as these different perspectives are related to working as an architect in a business context.

In the next chapter, we will start examining modern structured concurrency.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
An iOS Developer's Guide to SwiftUI
Published in: May 2024Publisher: PacktISBN-13: 9781801813624
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Author (1)

author image
Michele Fadda

Michele is currently working as a technical project and program manager at Eggon, an innovative startup in Padua, Italy, and as the director of FWLAB Limited, a UK App development studio. He specializes in skills such as Imperative Programming, Functional programming, Swift, Mobile Application Development. He started programming as a child with Assembly language and has worked for 20 years as a consultant using a variety of languages and technologies. He started developing for iOS with iOS on iOS v.3.0 in 2009. He has also developed many apps as a solo developer and has also participated in numerous projects.
Read more about Michele Fadda