Rinse the salted cod thoroughly and soak it in cold water for 24-48 hours, changing the water several times to remove excess salt.
Drain the cod and pat it dry. Remove any bones and skin, and shred the fish into bite-sized pieces.
In a large skillet or ovenproof dish, heat the olive oil over medium heat. Add the sliced onion and cook until translucent.
Add the minced garlic and cook for another 1-2 minutes until fragrant.
Layer the sliced potatoes on top of the onions and garlic. Cook for about 10 minutes, or until the potatoes begin to soften.
Add the shredded bacalhau to the skillet with the potatoes and onions. Stir to combine.
Season with salt and black pepper to taste.
Sprinkle black olives and chopped parsley over the top.
If using cheese, sprinkle it on top and bake in a preheated oven at 375°F (190°C) for 20-25 minutes, or until the potatoes are tender and the top is golden brown.
Optionally, you can serve with hard-boiled eggs. Boil the eggs, peel, and slice them to garnish the dish.
Enjoy your meal!