What is a handler?

HandlerTerminology

Handler Problem Overview


I am trying to learn some programming related terms, and I often come over the word "handler". Can anyone please explain what it means and when to use it?

Handler Solutions


Solution 1 - Handler

A handler is a routine/function/method which is specialized in a certain type of data or focused on certain special tasks.

Examples:

  • Event handler - Receives and digests events and signals from the surrounding system (e.g. OS or GUI).

  • Memory handler - Performs certain special tasks on memory.

  • File input handler - A function receiving file input and performing special tasks on the data, all depending on context of course.

Solution 2 - Handler

Code that's associated with and triggered by the occurrence of a specific event, like an incoming message, a thrown exception, a signal sent to a process, a network I/O request completing, or a mouse click on a user interface element. It's a very generic term.

Solution 3 - Handler

I think it's a very general term, without a 'hard' definition. The meaning is highly contextual, varies depending on the general code design.

For me, it usually means some code that is called from an inner core and is supposed to do some things and return. That 'inner' part can have several 'handlers' available, and chooses which one to call.

In some cases, you define some API to make those handlers mostly interchangeable, so the caller can pick one from a table and use the same code to call any of them. OOP helps a lot here.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiontjiView Question on Stackoverflow
Solution 1 - HandlersharkinView Answer on Stackoverflow
Solution 2 - HandlerAn̲̳̳drewView Answer on Stackoverflow
Solution 3 - HandlerJavierView Answer on Stackoverflow