1Class::Adapter(3) User Contributed Perl Documentation Class::Adapter(3)
2
3
4
6 Class::Adapter - Perl implementation of the "Adapter" Design Pattern
7
9 version 1.09
10
12 The "Class::Adapter" class is intended as an abstract base class for
13 creating any sort of class or object that follows the Adapter pattern.
14
15 What is an Adapter?
16 The term Adapter refers to a "Design Pattern" of the same name, from
17 the famous "Gang of Four" book "Design Patterns". Although their
18 original implementation was designed for Java and similar single-
19 inheritance strictly-typed language, the situation for which it applies
20 is still valid.
21
22 An Adapter in this Perl sense of the term is when a class is created to
23 achieve by composition (objects containing other object) something that
24 can't be achieved by inheritance (sub-classing).
25
26 This is similar to the Decorator pattern, but is intended to be applied
27 on a class-by-class basis, as opposed to being able to be applied one
28 object at a time, as is the case with the Decorator pattern.
29
30 The "Class::Adapter" object holds a parent object that it "wraps", and
31 when a method is called on the "Class::Adapter", it manually calls the
32 same (or different) method with the same (or different) parameters on
33 the parent object contained within it.
34
35 Instead of these custom methods being hooked in on an object-by-object
36 basis, they are defined at the class level.
37
38 Basically, a "Class::Adapter" is one of your fall-back positions when
39 Perl's inheritance model fails you, or is no longer good enough, and
40 you need to do something twisty in order to make several APIs play
41 nicely with each other.
42
43 What can I do with the actual Class::Adapter class
44 Well... nothing really. It exist to provide some extremely low level
45 fundamental methods, and to provide a common base for inheritance of
46 Adapter classes.
47
48 The base "Class::Adapter" class doesn't even implement a way to push
49 method calls through to the underlying object, since the way in which
50 that happens is the bit that changes from case to case.
51
52 To actually DO something, you probably want to go take a look at
53 Class::Adapter::Builder, which makes the creation of Adapter classes
54 relatively quick and easy.
55
57 The "Class::Adapter" class itself supplies only the two most common
58 methods, a default constructor and a private method to access the
59 underlying object.
60
61 new $object
62 The default "new" constructor takes a single object as argument and
63 creates a new object which holds the passed object.
64
65 Returns a new "Class::Adapter" object, or "undef" if you do not pass in
66 an object.
67
68 _OBJECT_
69 The "_OBJECT_" method is provided primarily as a convenience, and a
70 tool for people implementing sub-classes, and allows the
71 "Class::Adapter" interface to provide a guaranteed correct way of
72 getting to the underlying object, should you need to do so.
73
75 - Write more comprehensive tests
76
78 Class::Adapter::Clear, Class::Adapter::Builder, Class::Decorator
79
81 Bugs may be submitted through the RT bug tracker
82 <https://rt.cpan.org/Public/Dist/Display.html?Name=Class-Adapter> (or
83 bug-Class-Adapter@rt.cpan.org <mailto:bug-Class-Adapter@rt.cpan.org>).
84
86 Adam Kennedy <adamk@cpan.org>
87
89 • Adam Kennedy <adam@ali.as>
90
91 • Karen Etheridge <ether@cpan.org>
92
93 • gregor herrmann <gregoa@debian.org>
94
96 This software is copyright (c) 2005 by Adam Kennedy.
97
98 This is free software; you can redistribute it and/or modify it under
99 the same terms as the Perl 5 programming language system itself.
100
101
102
103perl v5.36.0 2023-01-20 Class::Adapter(3)