C patterns on data lifetime and ownership
Autor: | Christopher Preschern |
---|---|
Rok vydání: | 2019 |
Předmět: |
Stateless protocol
Programming language Computer science media_common.quotation_subject computer.software_genre Object (computer science) Advice (programming) Inheritance (object-oriented programming) Procedural programming Software design pattern State (computer science) Function (engineering) computer media_common |
Zdroj: | EuroPLoP |
DOI: | 10.1145/3361149.3361187 |
Popis: | Design patterns are well known for object-oriented languages. However, when it comes to procedural programming languages, like for example C, then most of the knowledge documented in form of design patterns cannot be used, because these patterns focus on object-oriented languages and in C you do not have mechanisms like a constructor, a destructor, inheritance, or public and private variables in form of memory dedicated to an object. Despite of that, also C programmers group their functionality into object-like elements which have their own dedicated memory and in C the programmers then have to put special attention on the lifetime and ownership of these object-like elements. This paper shows in form of patterns how C programmers can do that. The pattern Stateless Software-Module describes, how related functions, which don't share any information between the function calls, can be put together. Software-Module with Global State describes, how related functions can be put together as soon as they share information. Caller-Owned Instance describes how multiple object-like elements can be created and distributed to different callers. Shared Instance describes how the same can be achieved with additionally making it possible to share object-like elements between callers. The four presented patterns are throughout the paper applied to a running code example, to give hands-on advice on how C programmers can apply these patterns. |
Databáze: | OpenAIRE |
Externí odkaz: |