How Did I Manage to Write A Social Media App Without A Working API

I have been working on a social media application for about 4 to 5 months. It is really clear that for an social media application a working API is crucial. However, It has not been my case in the project . At least,not for first couple of months. Despite all of these facts, I’ve written the application successfully by following the rules that I will talk about.

Note : All of these are not my own rules, some of them are well known points when it comes to software development.

1- Clean Code :

You may say that what is the connection between clean code and having no api. You may be right at to some point. There is no connection between them directly. The connection is indirect. To make it clear, when you have an uncertian api, it is so likely that your customers( or api owners) does not determine the use cases of the application in detail which means they can change their mind in any time. Because of that, we need to refactor our code frequently and you may known that refactoring requires clean code. ( well it is not an obligation to refactor a code but refactoring a code which is not clean is really a nightmare)

2- SOLID :

Yes, again, our best friend SOLID principles. If you have read Clean Architecture by Robert C. Martin. You probably know that the modules like Network, Local data source etc should be just plugins for our application. In other words, If I decide to switch from Retrofit to Ktor for networking in the application, the main part of the application should not realize the change.

Using SOLID principles is important in our case since there is no working data source for us. We should keep design the interfaces in a way that the business rule classes or main parts of the application can use them without any dependency of the plugins.

Here Is an example from my case

As you can see, the MainViewModel does not need to know anything about the classes that implements the interfaces which means the changes in that classes do not affect the ViewModel. We can even provide dummy responses for the ViewModel which makes the ViewModel more testable.

3- Testing :

Speaking of testing, there is nothing to talk about actually. we need to test our code to know if it is still working or not. Also, as I said , the customers does not determine the requirements, business rules for the application and therefore refactoring is needed. While we are refactoring the code, how can we know that we do not break something working properly. By Testing of course.

Also we need to make sure that our Viewmodels,Converters and especially UI works correctly. Testing is the one of the best ways to do it so. When we test the components we have and be sure that they are working as aspected, the remaining job is integrating the missing parts to the classes we tested.

4- Avoid Duplicate Code :

This topic may seem as an element of writing clean code and it is actually but I believe it deserves to be talk about specifically.

Duplicate code is evil for all the areas of software. In many sources it is said that we as developers should avoid from it whenever possible. This was also valid for my case because there was no complete api as I said and things about networking classes changes all the time. I needed to write the codes in such a way that I would need minimum efford to adapt my code to any change.

As an really simple example. The api that I dealing with do not provide the image urls directly, instead it provides a base64 code as String for each image and the client should convert the code to url and use that url to load images. Any changes to the way to get image url can make clients to change whole image loading codes and guess what, It happened to me the image loading base url changed 1–2 times during development. Fortunately, I had created a utility function to deal with changes before.

5 — KISS:

Keep it simple stupid

Most of the social media apps are huge in perspective of lines of code. Because of the nature of the social apps, they tend to be complex and tend to have thousands of lines. . It actually does not matter if the api is working or not, things probably get difficul, speaking of my case. When the situation is like that, we really do not need to make anything more complex than it should be.

In the app, I tried to keep all the logic so simple that any developer could understand what is going on. Actually, the person that will read the code you wrote in the future is probably be yourself. So, Keeping the things simple will help you in fact.

All in all, I have shared my 5 rules that I followed in my project. The rules help me a lot to handle the project and finish it. I beleive that they probably help you too in your projects as well, so you may prefer to follow them in the future.

Stay tune for new blogs.

Love you all.

Take care.

Software Engineer, Mobile Developer.