The main duty of the batsman is to conserve his wicket as much as possible while trying to score as many runs as he can at a good rate. The aim is to try and keep a respectable run rate of about four or more runs per over which would result in a defendable total.
In an ODI the batting line-up is such that the opening batsmen are attacking players. While trying to wear down the new ball they also try to make use of the fielding restrictions in the first 15 overs.
The 3rd and 4th batsmen are probably the best in the team. Their role is to make sure that there is at least one batsman who has settled down and is scoring steadily and is set to play a long innings. This batsman also supports any new batsmen that come in and help them to settle in.
The middle order consists of batsmen that are very steady. These batsmen see the side through the middle part of the match where they keep the scoreboard ticking with singles and doubles rarely scoring a boundary. They help to lay down the foundation for attacking batting in the final 15 overs.
The batsmen take more chances in the final 15 overs trying to maximise the run rate. The tail end batsmen are mainly bowlers who do not have much batting skills. They are encouraged to let loose and go for boundaries as as result they are known as pinch hitters.
In a test match there is no haste to score runs. The batsmen take their time to settle in and try to score as much runs as possible. The opening pair are technically sound and solid. They wear down the new ball and try to stay on top of the bowler friendly conditions on the opening day.
The next batsman in is also technically sound and should be capable of playing a very long innings trying to maintain stability at one end. The upper middle order are also capable of playing long innings. If a wicket is dropped nearer the end of the days play a fairly capable tail ender is sent in as the 'night watchman' to see through the end of the day without the loss of more wickets.
If the batting team has set a good 1st innings total then in the third innings it will try to score aggressively to increase the total runs scored in as few balls as possible. This normally occurs on the fourth day.
The opposing team is sent in to bat near the final few hours of the day. This tactic results in the team batting last having to deal with a high total and the bowling side having an ample number of overs to try and bowl out the batting side.
If the team batting first has not managed to score a respectable total and is behind on the fourth day, then the strategy reverts to defence where the batsman will play extremely cautiously and bat out as much time as possible so that come the end of the 5th day the match will end in draw as the allocated time runs out.