Start by soaking the salted codfish in cold water for about 24 hours, changing the water 2-3 times to remove the excess salt. Once soaked, drain the codfish and pat it dry.
Preheat your oven to 375°F (190°C). In a large pot, bring water to a boil and cook the codfish for about 10 minutes until it becomes flaky. Remove from heat and let it cool slightly. Then, remove the skin and bones and break the codfish into bite-sized flakes.
In a separate pot, bring water to a boil and cook the sliced potatoes for about 5 minutes until they are slightly tender. Drain and set aside.
In a skillet, heat olive oil over medium heat and sauté the onion and garlic until they become translucent and fragrant.
In a saucepan, combine the milk and heavy cream and heat over medium heat until it becomes warm (do not boil).
In a separate bowl, whisk the flour into a small amount of the warm milk mixture to create a slurry. Gradually pour the slurry into the saucepan with the remaining warm milk mixture, whisking constantly until the mixture thickens and becomes smooth. Season with salt and pepper to taste.
In a large baking dish, layer half of the sliced potatoes, followed by half of the codfish flakes and sautéed onions mixture. Pour half of the creamy sauce over the layers. Repeat the layering process with the remaining potatoes, codfish, onions, and sauce.
Sprinkle the shredded cheese on top of the final layer and place the baking dish in the preheated oven. Bake for about 30-35 minutes or until the cheese is golden and bubbly.
Once done, remove from the oven and let it cool slightly. Garnish with chopped parsley if desired.