Repositories and Data Access Objects are still alive

In my previous articles when I was talking about Clean architecture and Domain Driven Design I mentioned one piece of domain layer – repository or more precisely repository pattern. The repository pattern is used to persist and retrieve domain models. Although repositories are mostly related to Domain Driven Design the other architectures might have the objects with the same functionality but are called different. In Fitradar application (front end and back end) the objects that are used to persist data in the database and fetch data from the database and map data to in-memory objects (aka POCO – Plain Old C# Object, POJO – Plain Old Java Object) and are not part of the Domain layer are called DAO (Data Access Objects). DAO usually are used in cases when no business logic is involved and the application needs to execute simple CRUD operation.

In Android application to work with database we use Room Persistence library but in our back-end solution we use Entity Framework Core. These two are know as Object-relational mappers or ORM. And today I wanted to explore the relationship between Domain Repositories, Data Access Objects and ORM and share some experience we had in our team working with these patterns and libraries.

If you look at the responsibilities of Repository, DAO and ORM they are very close to each other. Some years ago when ORM technology was in its inception the DAO and Repositories usually were working directly with the low level database access services. In case of .NET it was ADO.NET library and in case of Android it was SQLite library. And it was quite clear that DAO or Repository should use these libraries to persist or retrieve in-memory objects and map the data. But now-days when in application development main data access technology became ORM the border between ORM and DAO and Repository has become very blur, especially when one just switched to ORM. Working with ORM in different projects and languages our team came to conclusion that in same cases ORM can fully replace the DAO or Repository and can be used instead of it. Let’s look closer at the cases when it is appropriate to use just a ORM library and when the DAO or Repository should be used in combination with ORM:

  • If you need to save, update or delete single flat plain old object then in most cases ORM library will do the job for you. Of course EF Core and Room are capable of doing more, but then we really should investigate each case separately
  • If you need to fetch the data from single table by primary key then again in most cases you can fully relay on ORM
  • In case Domain layer aggregate has complex entity cluster hierarchy, where different entities might have different persistence state you most likely will need to write such aggregate persistence logic by yourself either using ORM or low level database access library. In our application one such aggregate is Sport Event that has Place and Organizer and some other entities. And the problem we faced when tried to save Sport Event by using built in EF Core capabilities was the different Entity State and the calculated state before Save operation. For example we had cases when we needed to create a Sport Event in Place that was not yet saved in database, and since both entities have the same Entity State EF Core tackled that case well and was able to create both entity records in database. But the problem started to appear when we wanted to create Sport Event in the Place that already had other Sport Events, now before saving aggregate Sport Event we had to fetch Place entity to make sure EF Core sets the correct Entity State. And the more entities your aggregate root has the more fetch operations might be needed. So in this case for us seemed obvious putting Entity State synchronization logic in separate Repository.
  • In case data query logic and following mapping logic is so complex that to make a code readable it is necessary to split logic in separate functions, you most likely will move those functions to separate class, Data Access Object, to persist the Single Responsibility principle.

As you can see the Repository and DAO still has their place in the modern software architecture. In case of queries in CQSR architecture query logic might be put in Application layer since anyway contrary to Commands, Queries only responsibility is data fetching, and that duplicates DAO responsibility. By choosing to put query logic in Application layer we make a direct dependency on EF Core. That is not a problem in classical three layer application, but it does not fit the Clean Architecture principle where Application layer should be aware only of Domain layer and with outer layers (EF Core belongs to the Infrastructure layer) communicates only through interfaces. In this case we should use DAO.

Please visit our website and join the mailing list. Our app is coming soon:

http://fitradar.me/

Study: fitness boosts brainpower in adults

Physical fitness has been associated with better brain structure and brain functioning in adults.

The findings of a study, led by Dr Jonathan Repple of the University Hospital Muenster in Germany, suggests that increasing fitness levels through exercise could result in improved cognitive ability – such as memory and problem solving – as well as improved structural changes in the brain.

A group of researchers led by Repple used a publicly available database of 1,200 MRI brain scans from the Human Connectome Project and combined it with physical testing to assess the subjects’ physical fitness. Each one’s cognitive ability was also measured. The researchers excluded subjects with pre-existing conditions, such as neurodevelopmental disorders, diabetes or high blood pressure.

The results of the study showed that physical endurance was positively associated with the global cognition scores of the subjects taking part.

In its conclusion, the group of researchers said the results of the study suggest that physical exercise could be used as a form of preventative healthcare.

“The observed pattern of results appears to support the notion of a beneficial effect of physical fitness on cognitive function,” the study reads.

“This notion is supported by the few available experimental studies indicating that physical exercise leads to increases in memory performance and brain structural integrity.

“This concept might be of relevance for a wide range of domains in health and life sciences including prevention, clinical care and neurobiological research.

“Along with previous findings, our findings point to the potential of physical fitness as a modifiable factor that might be applied as an intervention in prevention and clinical care.”

The report was simultaneously published in the Scientific Reports journal and presented at the ECNP Congress in Copenhagen, Denmark.

To read the study in full, click here.

Source: http://bit.ly/30Pqjy3

Please visit our website and join the mailing list. Our app is coming soon:

http://fitradar.me/

50 Great Reasons To Exercise

  1. Lifts your mood
  2. Improves learning abilities
  3. Builds self-esteem
  4. Keeps your brain fit
  5. Keeps your body fit & able
  6. Boosts mental health
  7. Boosts your immune system
  8. Reduces stress
  9. Makes you feel happier
  10. Has anti-aging effects
  11. Improves skin tone and colour
  12. Improves sleeping patterns
  13. Helps prevent strokes
  14. Improves join function
  15. Improves muscle strength
  16. Alleviates anxiety
  17. Sharpens memory
  18. Helps to control addictions
  19. Boosts productivity
  20. Boosts creative thinking
  21. Improves body image
  22. Gives you confidence
  23. Helps you keep focused in life
  24. Improves eating habits
  25. Increases longevity
  26. Strengthens your bones
  27. Strengthens your heart
  28. Improves posture
  29. Prevents colds
  30. Improves appetite
  31. Improves cholesterol levels
  32. Lowers risk of (certain) cancers
  33. Lowers high blood pressure
  34. Lowers risk of diabetes
  35. Fights dementia
  36. Eases back pain
  37. Decreases osteoporosis risk
  38. Reduces feelings of depression
  39. Prevents muscle loss
  40. Increases energy and endurance
  41. Increases sports performance
  42. Increases pain resistance
  43. Improves balance and coordination
  44. Improves oxygen supply to cells
  45. Improves concentration
  46. Helps with self-control
  47. Lessens fatigue
  48. Increases sex drive & satisfaction
  49. Makes life more exciting
  50. Improves Quality of Life

Visit our website and join the waiting list. Our app is coming soon:

http://fitradar.me/

10 Things Your Personal Trainer Won’t Tell You

Sometimes it can feel nearly impossible to get yourself in shape, which is why personal trainers are so helpful. Not only do they give you that extra push, but you also get the benefits of their expert knowledge and experience. Even with their guidance, however, your efforts will be in vain if you aren’t following the right diet and fitness regimen for you. To find out exactly how you can improve your fitness routine, WD spoke with top-notch personal trainers for their secrets to getting the most out of your workout and living an overall healthier life.

1. Set realistic goals and be confident.
Before starting your path to a healthier lifestyle, it’s important to be realistic about how much time you have for the results you want, and how you can achieve them. Colleen Faltus, private trainer at The Sports Club/LA in Boston, suggests compiling “a list of both short- and long-term goals. This will keep you motivated to accomplish and surpass them; it will give you focus and add some variety to your workout.” Another trick to staying focused? Be confident! Trainer Bill Trimble, founder of the workout program Extreme Bill Trimble, says, “if you’re not confident and determined you can achieve your goals, you won’t. Make sure you try to stay positive and keep your head up, even on those rough days.”

2. Get specific about what you want to achieve.
Although you may think your trainer will automatically know what you want, that isn’t the case. Trimble says telling your trainer exactly what your goals are is the key to success. A weight-loss plan, for instance, will be different from a plan for someone trying to build muscle. Your trainer will design a routine based on your individual needs and lifestyle, so letting him or her know exactly what you want up front will help you get the most out of the experience.

3. Have fun!
“Working out should be enjoyable. Your personal trainer is there to push you a little bit, but not intimidate,” says Trimble. During your initial consultation, talk with your trainer about activities you enjoy, your schedule and exercises you don’t particularly like. This way, he or she can devise a routine you’ll love. Another key factor to having fun is variation. “Incorporating other elements of fitness besides cardio will increase the likelihood of faster and more efficient weight loss,” explains Faltus. Another plus? You’re less likely to become bored if you try new things.

4. Performing each exercise correctly is imperative, so watch your form.
To achieve the best possible results and stay injury-free, follow your trainer’s instructions about proper form. This is especially important if you’re doing an at-home workout on your own. “Model the video or demonstration exactly, paying special attention to the trainer’s breathing technique and form,” Trimble urges.

5. You should begin to see results within 12 weeks.
Depending on your workout plan, the three-month mark can be a good indicator of how you’re doing. “In about 90 days, you should be able to notice results—whether it be that your jeans are a little looser, your quality of sleep is better or you just feel good all around,” Trimble says. Many people lose motivation if they don’t see results sooner, but you’re changing your physique, so 12 weeks is about how long it will take before your workouts begin building lean muscle.

6. Communication is the key to success.
As with any relationship, communication is vital when it comes to a healthy and happy experience. Faltus recommends giving your trainer feedback about how you are or aren’t liking the exercises, what is or isn’t working and anything else that’s on your mind. Most often, your trainer will check in with you before and after the workout. So use the opportunity to talk! “You know your body better than anyone else, so speak up at each session and your experience will be that much more enjoyable and exciting,” Faltus says.

7. You’re going to have bad days.
“You’re going to fall off the wagon and have off days at some point,” says Trimble. “But get right back up and begin again without getting discouraged.” The biggest problem trainers see in their clients is that their emotional confidence starts to dwindle when something goes wrong. “You have to believe in yourself and [believe] you can do it,” Trimble says. So, if you splurge on your eating one weekend, don’t beat yourself up—just give it your all during your Monday workout session.

8. If you don’t have a trainer, you can still stay motivated.
On those mornings when you just can’t get yourself out of bed, it’d be pretty nice to have a trainer waiting for you at the gym. But you don’t need a trainer if you know how to find motivation elsewhere. For one thing, Trimble recommends working out with a partner for extra encouragement. He also suggests choosing a fun workout so you’ll look forward to it. “These days, so many programs are easily accessible, such as at-home boot camp workouts, circuit training, online videos and specific plans such as the P90X workout.” And perhaps most important, be consistent. If you exercise on the same days every week, not only can you schedule around your workout, but you’ll be more likely not to miss it.

9. You have to eat right, too.
Personal trainers aren’t miracle workers, so after you leave the gym, make sure you follow the diet plan you’ve established for yourself (or with the help of a dietician). One way Trimble helps his clients eat right is by encouraging them to keep a food journal. “Nutrition can be a problem, so writing it down and being able to look at it with my clients is helpful,” he says. Not only will you be able to discuss what you’re eating with your trainer, but you’ll also become more aware of your food choices—and rethink that second piece of cake! One way Faltus suggests you start a good nutrition plan? Let yourself cheat. “Eating balanced meals filled with fruits, vegetables, grains and protein will prove successful in the long run. But remember to give yourself a ‘cheat’ nutrition day on the weekends.”

10. You’re probably not getting enough sleep.
“Lack of sleep causes a decrease in energy and motivation to accomplish both short- and long-term goals.” Not only are proper sleeping habits important for you mentally, but if you don’t rest your muscles properly before and after a good workout, you risk injury. Faltus says to “adjust your sleep schedule and get both quality sleep and a decent quantity of sleep. You’ll notice the difference in your overall performance, and your muscles will thank you too.” For some tips on how you can destress and unwind before bed to sleep better, click here.

Source: https://bit.ly/35QuewC

Please visit our website and join the waiting list. Our app is coming soon: http://fitradar.me/

Logging in our application

Any application to some extent is using the logging system. And we are not an exception. We log a lot of information in our Android and iOS applications as well as in our backend server application. But what logs give us, after all, they are not contributing to the application functionality? They might be a part of user requirements, but why would anyone want to invest money and time for the feature that is not used by a user? Let’s explore the purpose of logs in software development and practices developers are applying.

Here are some of the cases where we are using logging in our applications:

  • during development to make it easier and faster spot a bug along the
    • @NonNull and other annotations and code inspection tool Lint
    • unit and integration tests, where we try to cover most of the code execution paths and integrations points. (And I already wrote how we approached the testing in our project)

    we use logs that show as the trace of actions and values that led to a particular bug. But before we started to use logs we had to answer the following questions:

    • where to put log statements on
    • what information to log

    Since a lot of our code is covered by unit tests then there is little reason to log our own code for debugging and test purposes, but where we don’t have control over the values we are processing is:

    • framework lifecycle methods, like onCreate, on ViewCreate, onResume, onPause in Android application. If our code is using the arguments provided by lifecycle method we log these values and assert the expected value if it is possible
    • to click listeners and other event handlers
    • third party library methods and their returned results. For example, for network calls we are using Retrofit and we always log the network requests and responses in debug build variant. Another example calls to the database. Since we are using Room in Android application, we want to see SQL code sent to the database

    So once we log enough information we can spot the bug just by going through logs and skipping the process of starting the app again with attached debugger and stepping through the code. And we don’t have to worry much about the performance as well since Android logging system is taking care of debug log statements and skip them at runtime.

  • in production:
    • to monitor, on the back end server the logs are used to monitor the normal business logic functionality. We log every request. If the request is successful we log it as info, in case request ends up we log error. When the error is reported on the back end service, the gathered logs are of great value. Very often they allow to spot the problem without further investigation.

    • we log fatal errors, that caused the application stop. On the backend server, we catch the exceptions as early as possible and when the exception is caught it is logged and an email is sent to an administrator. We don’t experience many exceptions outside of our app on the back end part, because the only reason that can lead to such exception is a malformed request and not the back end code itself, and since the request is formed by third party library it is very rear that it is malformed. A different story is with uncaught exceptions on the client – Android or iOS app. It is not possible to catch all the exceptions so they leak and cause the app to crash. To log these kinds of exceptions we use Fabric Crashlytics (Firebase). These logs later help us a lot to find a cause of a crash.

Visit our website and join the mailing list! Our app is coming soon:

http://fitradar.me/