class ParentClass{ private List<string> _childClassList; public ParentClass() {
class ParentClass{ private List<string> _childClassList;
public ParentClass() {
///Create the new list object in constructor
_childClassList = new List<string>();
} /******************************* * Here are all the behaviors * of the ParentClass object *******************************/ public int GetChildClassCount() {
return _childClassList.Count;
} public void AddToChildList(string val) {
_childClassList.Add(val);
} public string GetLongestStringInChildClassList() {
string longestString = String.Empty; foreach(string member in _childClassList) { if(member.Length > longestString.Length) longestString = member; } return longestString.ToUpper();
string longestString = String.Empty;
foreach(string member in _childClassList)
{
if(member.Length > longestString.Length) longestString = member;
if(member.Length > longestString.Length)
longestString = member;
}
return longestString.ToUpper();
}}
class ParentClass{ ///Notice here I substitute the List for a ///ChildClassCollection private ChildClassCollection _childClassList; public ParentClass() {
///Create the new collection object in constructor _childClassList = new ChildClassCollection ();
///Create the new collection object in constructor
_childClassList = new ChildClassCollection ();
} /******************************* * Here are all the behaviors * of the ParentClass object *******************************/ public void DoStuff(string input) {
if( input.ToUpper() == _childClassList.GetLongestStringInChildClassList() ) {///Do stuff here }
if( input.ToUpper() == _childClassList.GetLongestStringInChildClassList() )
///Do stuff here
class ChildClassCollection{ ///The string list gets put in the Collection Class ///This creates an extra layer between your code ///and .Net "Primitives" private List<string> _childClassList; public ChildClassCollection() { _childClassList = new List<string>(); } public int GetChildClassCount() {
string longestString = String.Empty; foreach(string member in _childClassList) { if(member.Length > longestString.Length) longestString = member; }