HOME

TheInfoList



OR:

In
object-oriented programming Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of ...
, a helper class is used to assist in providing some functionality, which isn't the main goal of the application or class in which it is used . An instance of a helper class is called a helper object (for example, in the
delegation pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows object composition to achieve the same code reuse as inheritance. In delegation, an object handles a request by delegating to a second object (the ''de ...
). Helper classes are often created in introductory programming lessons, after the novice programmer has moved beyond creating one or two classes. A utility class is a special case of a helper class in which the methods are all static. In general, helper classes do not have to have all static methods, but may have instance variables. Multiple instances of the helper class may exist as well.


Example

This is also an example of a utility class. public static class PrependHelper


Alternative to helper class

Functions which are going to helper classes could be placed close to where they are used. The other alternative is wrapping helper class parameters into a class as a field. That class can have a name from the business domain connected to the fields it has. The example below shows how to convert helper methods to methods on domain types: public class Text


See also

* Hierarchy *
Class diagram In software engineering, a class diagram in the Unified Modeling Language (UML) is a type of static structure diagram that describes the structure of a system by showing the system's classes, their attributes, operations (or methods), and the rela ...
(UML) *
Class-based programming Class-based programming, or more commonly class-orientation, is a style of object-oriented programming (OOP) in which inheritance occurs via defining ''classes'' of objects, instead of inheritance occurring via the objects alone (compare prototy ...
{{Types of programming languages Class (computer programming)