There are a couple of ways you can look at this, both from an in story explanation, as well as a real world application.
In story the purpose of the siege was to bait the Night King into entering the field of battle so ultimately the dragons could kill him. Bran was used as bait because the Night King has a ridiculous need to kill him (if someone can explain, why exactly the NK needs to kill Bran, please do). Basically the way the battle played out more or less worked as planned.
Now there are a number of issues here with doctrine in a fight (how battles are actually fought in this equivalent time period), and the Strategy and Tactics taken. Just a quick aside Strategy is a long term goal, like a campaign strategy and why some battles need to be fought, and tactics are short term, move this unit here for this reason. Example being, a tactic is to order a tank division to hold a bridge, the strategy being forcing the enemy to move forces from the east to the west because of less ways to traverse a feature, in this instance the river.
This is going to get really long... so I'm just going to do a quick dirty on what the defenders did wrong and how they wouldn't really make those mistakes if they were suited to leading men in battle, and an explanation on how it would be done, both with knowing and not knowing the enemy.
What was done wrong:
Dothraki Leading the Charge:
The defenders don't know the abilities of the White Walkers in open battle, while the thinking here is that the Dothraki are probably the best units in the entire series, and definitely the best on open fields, they are incredibly poorly suited to the role of running down an advancing army. The Dothraki often use speed and violence of action, charging into ill-prepared Armys and terrifying them off the field quickly. The White Walkers aren't people, and most of the planners of the battle knew this, this was a major blunder. Also the Dothraki cut through lines, if they are facing an attacking army, there is no line to cut through and get to the other side.
These guys are loosely based on Mongolian Horse back warriors. I say loosely because they completely forgot that it's not the Mongol sword that won them the largest land empire in history, it's the Mongol composite bow. But the main Mongol tactic was to trick the enemy into thinking their numbers were smaller, drawing advancing enemies into thinking their lines were breaking, and then as the enemies advanced into being surrounded the Mongols would shoot them with arrows until they died. Near the ends of battles the Mongols often left breaks in their encirclement, letting the enemy think they had a way to escape, and then they would run them down and butcher them as they were tired. Be like the Mongols, not the Dothraki. Dothraki operated ultimately on fear, useless against White Walkers.
The Defenders never ranged their "Artillery": The trebuchet and catapult were never ranged, and THEY ONLY FIRED THEM ONCE. Oh, and they placed them essentially on the front lines, near the castle walls/inside the walls/behind Winterfell all would have been better positions. They would have been ranged and they would have known exactly how to fire each one to hit exact positions, so they could have been used in the midst of fighting.
Combining troop types on the same line with same conditions: This sounds odd to you, but the Unsullied holding the left and the Northmen holding the right is ultimately stupid. The Unsullied are the best for holding a defensive position, they should have held the line and immediate flanks. The Northmen operate more as skirmishers, heavy unmounted knights. They would be best used to fill gaps, cover the extreme flanks, etc... They'd have no issue continuing a line, but wouldn't be able to stop an advance. Also these would be the first troops you want back in your castle during a retreat. Holding a wall doesn't require a shield, the wall is your shield.
Where are the Archers: Why aren't mass quantities of arrows being poured into this completely unarmored Army?
Why do the walls not getting defended after the field fell?: This goes along with how poorly Winterfel is designed. Number one men should be on the walls to repel climbers, archers should be in the towers to provide fire on opposing walls. Yes opposing walls they should know that star shaped fortification have been en vogue forever, so defenders don't have to expose themselves to fire down their walls, they simply fire on the walls across from them they can see. Winterfel doesn't have this, because siege warfare isn't a thing in Westeros I suppose. No Oil to pour on hapless White Walkers, no murder hatches... If you are interested, just research what goes in to attacking a fortified structure, and the defenses thought of through the years. That's why siege's are usually done in a waiting for a year outside your walls manner.
And the biggest sin:
Why is there no plan for fall back points and defenses? Real defenses have fall back points, and contingency fall back points. Castles have Keeps, even if the castle walls fall, Keeps can be sealed essentially tight and are extremely difficult to get into. There are stories in history of sections of walled cities and castles falling, while other sections are still held, it's that difficult to get from one area to another. This was never done by the Defenders.
How this would have played out: In the days leading up to the battle, skirmishing parties of militia men, recon, wildlings would have been sent out to engage and harass the enemy to slow their advance and determine how they are ultimately going to fight. The people I mentioned are ultimately easily expendable because they don't really fit a mold of the type of troop needed to defend a castle.
Considering they wouldn't have learned the white walkers abilities until days before battle, the outer defenses created would still likely be the same, but they need to be bigger and more pronounced. The trench dug would be deeper with more wood and more designed to stop a rush. The artillery would have been placed in the yard and near the wall and ranged. The unsullied would have been used to hold the whole line with the Northmen on the flanks and as reserve. AFTER the white walker charge had been halted you would use your cavalry Dothraki to crash into their flanks endlessly, in and out. They would attack enough to keep them from gaining forward momentum and thin them out, but no enough that they would and change angle of attack. When the field lines broke and retreating within the walls was needed, the Northmen would go first, the Dothraki would be told to break off and constantly attack at the rear of the White walkers, basically run around and pillage the country side, but pillage for enemies obviously.
Once inside the walls the Northmen would be on the walls to repel climbers, while the remaining unsullied would be at strategic hardpoints, the main entrance, travel ways between different parts of the castle, anywhere a line needs to be held. Ultimately the plan would be to continual funnel the white walkers into pinch points, since the white walkers are useless at actually siegeing.