The most basic elements of a door latch are a movable metal wedge and a slot across from it that it fits into. The idea is that the metal wedge, when it is fully extended out from the door, will catch in the slot across from it in the frame of the door. When this happens, the door will be held in place and will be unable to open. This wedge, however, should be retractable, so that it can pulled back. This will release the door and allow it to open freely. This retractable wedge should be designed so that it fits snugly into the slot. Otherwise, it will be possible to force the door open simply by jarring the door and dislodging the wedge. On the other hand, the wedge will need to be able to be easily and completely retracted, otherwise the door may get "stuck" shut.
Retracting the latch
In theory, the latch should essentially have two main positions: fully out and fully retracted. The mechanism for controlling this is the doorknob. A doorknob consists of the knob itself, as well as the middle part, called the shank. The shank contains another part, called the spindle, which is involved in pushing out and retracting the latch. When the knob turns, the shank rotates, which causes the spindle to either move forward or backward. As the spindle moves forward, the latch goes out where it can catch in the slot, and when the spindle moves backward, the latch retracts, which then allows the door to open.
Latches and locks
The most basic type of lock involves a button or switch that keeps the latch fully out. Most locks (that aren't deadbolts) are activated by pressing a button or turning a switch. This causes a small part of the lock, called a tang, to be partly in and outside of the shank. This prevents the shank from rotating, which "locks" the latch into place. The tang will not go back inside the tang until the button or switch has been released, or until the proper key has been inserted into the door.