00001 /* 00002 * Copyright (c) 2000, 2020, Oracle and/or its affiliates. 00003 * 00004 * Licensed under the Universal Permissive License v 1.0 as shown at 00005 * http://oss.oracle.com/licenses/upl. 00006 */ 00007 #ifndef COH_DESCRIBABLE_HPP 00008 #define COH_DESCRIBABLE_HPP 00009 00010 #include "coherence/lang.ns" 00011 00012 00013 00014 COH_OPEN_NAMESPACE2(coherence,util) 00015 00016 00017 /** 00018 * Abstract Object extension that simplifies the implementation of toString() 00019 * for class hierarchies. 00020 * 00021 * Subclasses of Describable should implement the getDescription() method 00022 * by outputing a delimited list of name-value pair(s) representing the class' 00023 * state. Further subclasses should override the getDescription() by first 00024 * delegating to the parent class' implementation and then outputing their own 00025 * state. 00026 * 00027 * For example, consider a class hiearchy consisting of parent class A and 00028 * child class B. Class A should implement getDescription() as follows: 00029 * <pre> 00030 * String::View A::getDescription() const 00031 * { 00032 * return COH_TO_STRING(super::getDescription() << "Member1=" << m_hMember1 << ... << ", MemberN=" << m_hMemberN); 00033 * } 00034 * </pre> 00035 * Class B would then override this method as follows: 00036 * <pre> 00037 * String::View B::getDescription() const 00038 * { 00039 * return COH_TO_STRING(super::getDescription() << "MemberN+1=" << m_hMemberN1 << ... ); 00040 * } 00041 * </pre> 00042 * 00043 * @author jh 2008.02.13 00044 */ 00045 class COH_EXPORT Describable 00046 : public abstract_spec<Describable> 00047 { 00048 // ----- Describable interface ------------------------------------------ 00049 00050 public: 00051 /** 00052 * Return a human-readable description of the state of this class in 00053 * the form of a delimited list of name-value pairs. 00054 * 00055 * The default implementation returns an empty string 00056 */ 00057 virtual String::View getDescription() const; 00058 00059 00060 // ----- Object interface ----------------------------------------------- 00061 00062 public: 00063 /** 00064 * {@inheritDoc} 00065 */ 00066 virtual TypedHandle<const String> toString() const; 00067 }; 00068 00069 COH_CLOSE_NAMESPACE2 00070 00071 #endif // COH_DESCRIBABLE_HPP