Content deleted Content added
→C#: use file-scoped namespace |
→See also: add portal |
||
(6 intermediate revisions by 5 users not shown) | |||
Line 1:
{{Short description|Software creational design pattern}}
{{for|the article about a general pool|Pool (computer science)}}
The '''object pool pattern''' is a software [[creational pattern|creational design pattern]] that uses a set of initialized [[Object (computer science)|objects]] kept ready to use – a "[[Pool (computer science)|pool]]" – rather than allocating and destroying them on demand. A client of the pool will request an object from the pool and perform operations on the returned object. When the client has finished, it returns the object to the pool rather than [[object destruction|destroying it]]; this can be done manually or automatically.
Line 35 ⟶ 36:
== Pitfalls ==
Care must be taken to ensure the state of the objects returned to the pool is reset back to a sensible state for the next use of the object, otherwise the object may be in
Stale state may not always be an issue; it becomes dangerous when it causes the object to behave unexpectedly. For example, an object representing authentication details may fail if the "successfully authenticated" flag is not reset before it is reused, since it indicates that a user is authenticated (possibly as someone else) when they are not. However, failing to reset a value used only for debugging, such as the identity of the last authentication server used, may pose no issues.
Line 179 ⟶ 180:
private DateTime _createdAt = DateTime.Now;
public DateTime CreatedAt => _createdAt;
public string TempData { get; set; }
Line 327 ⟶ 325:
== See also ==
{{Portal|Computer programming}}
* [[Connection pool]]
* [[Free list]]
Line 362 ⟶ 361:
[[Category:Software optimization]]
[[Category:Articles with example C Sharp code]]
[[Category:Articles with example Java code]]
|