The Roman warfare developed the same way as the way they armed themselves. Always ready to learn from others, mostly their enemies. The Phalanx was one of the first ways to organize an army that changed the Roman warfare.

Phalanx
The phalanx is number of parallel rows of warriors, who stand shoulder to
shoulder, so they are protected by the shield of the man to their
right. According to Polybius
there could be up to 16 rows. Only the
first 4 or 5 rows could actually participate in the fighting.The men
in the rows behind would push the men in front forward or kept them in
place. This technique made it impossible for the men in front to leave
their place and very hard for an enemy to push the phalanx backwards.
But maneuvering with a phalanx other than moving forward was almost
impossible. In fact a phalanx was a wall made out of men and like a
wall it worked at its best on even terrain. An like a wall once
breached it would collapse.
The Roman learned this technique from the Etruscans and would
successfully use it against them.
Samnite way
The inflexibility of the phalanx became a problem when the Samnites
became their enemies. The Samnites operated with much smaller units and
had the nasty habit of throwing javelins. In a phalanx there is no room
to duck; all you can do is trying to block the javelin with your
shield. The Roman not only copied the armament of the Samnites they
also adapted their way of organizing their army. Again the Roman warfare changed dramatically. The maniple now became
the basic tactical unit. Between two maniples was left a gap about the
size of a maniple. Behind that line with the hastati was the second
line with the principes but shifted to the right so that these
maniples were facing into the gap. Behind that line was the third line
of the triarii shifted to the left again.

In his Histories 18.28 Polybius makes a good comparison between the phalanx and the Roman warfare. Also T. Livius gives a good description of the new organization.
In his Ab urbe condita 8.8 he places this reorganization of Roman warfare however long before the first war with the Samnites in 340 BC: Soldiers pay was instituted in 406 BC. This is unlikely because they then wouldn't have had a good chance to study the Samnite way of warfare.
Room needed
To be able to throw their javelins, but also to be able to wield their
swords, the legionnaires needed more space than a warrior in a phalanx,
who only had to thrust and pull his spear. The space between two
legionnaires
was about 1 meter.Polybius points out that 1
legionnaire thus faced 10 enemy spearheads, but due to the flexibility,
a maniple could fall back without urging the rest of the legion to do
immediately the same and the Roman option of reinforcing of units that
were in trouble they got the upper hand in most of their battles.

From march formation to battle formation
When on the move it happened in files of three men. When changing from march order
into battle orde, the centuries would mach up at the side of the
intended battlefield. When arriving at the desired line they turned
left (or right) and marched along that line until they reached their
place. All they now had to do was to turn about to face the
enemy. During this process that could easily take several hours the
legion was vulnerable. To give the legion some protection there
was a screen of velites in front of the legion using slingshots and javelins.
Battle begins
Then when it was time to engage the enemy the legionnaires would make
as much noise as they could; screaming and with their swords beating
against the shields. In the later days it was just the opposite
complete and disciplined silence. Depending on the orders they awaited
the enemy to attack or marched towards the enemy while the velites were
pulled back through the lines. The Roman aggressive mentality made
waiting for the enemy a rare.
When the enemy was close enough the javelins were thrown, the swords drawn and the close , hand to hand combat begun.
Relieve
The men in the phalanx had no option but to keep fighting until they
won or got wounded or killed. Though Nicolò Macchiavelli
in the 16th
century failed to prove, with a real army, that this was possible, the
room between the Roman soldiers must have made it possible for the
second row of soldiers to relieve the soldiers in front. Probably a
matter of training and discipline. It is very unlikely that commanding
officers pulled back a unit to rest. This would have been seen as a
flight a very bad for the moral.