提交 b5bf9291 编写于 作者: L Lucas Meneghel Rodrigues

avocado.utils: Introduce data_structures module

Introduce a module with useful classes for use inside
avocado core code or plugins. We start with the Borg
class, a design pattern considered to be better than
the Singleton [1]

[1] http://www.aleax.it/5ep.htmlSigned-off-by: NLucas Meneghel Rodrigues <lmr@redhat.com>
上级 16627559
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See LICENSE for more details.
#
# Copyright: Red Hat Inc. 2014
#
# Authors: Ruda Moura <rmoura@redhat.com>
# Lucas Meneghel Rodrigues <lmr@redhat.com>
#
"""
This module contains handy classes that can be used inside
avocado core code or plugins.
"""
class Borg:
"""
Multiple instances of this class will share the same state.
This is considered a better design pattern in Python than
more popular patterns, such as the Singleton. Inspired by
Alex Martelli's article mentioned below:
:see: http://www.aleax.it/5ep.html
"""
__shared_state = {}
def __init__(self):
self.__dict__ = self.__shared_state
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册