Sunday, 27 July 2014

Patterns

Finally bought myself a patterns book, lots of wow and that is very clever moments and to get the best out of it a number of re-reads is a must. 

Factory, prototype, adapter, chain of responsibility and singleton I can see how they can be useful, they make a lot of sense. Some others will have to be left until I can go through them again




Little bits, looking through pluralsite agile courses the agile manifesto was mentioned which I have signed. 

Doing other reading about collection types, just how easy it is to implement a list, stack, queue, once the concept of a node is understood, I made my own list!

Hopefully this then makes it easy to see that you can add lots of different methods for push, pop, enqueue, dequeue, contains etc.

namespace basicsTests
{
    class Program
    {  
        static void Main(string[] args)
        {
            var firstNode = new aNode<string>("first string");
            var secondNode = new aNode<string>("second string");
            var thirdNode = new aNode<string>("third string");

            var someList = new aList();
            someList.add(firstNode);
            someList.add(secondNode);
            someList.add(thirdNode);

            someList.displayList();
            Console.Read();
        }
    }

    class aNode<T>
    {
        public object stored;
        public aNode<T> nextNode { get; set; }

        public aNode(T objectToHold)
        {
            stored = objectToHold;
        }
    }

    class aList
    {
        aNode<string> headNode = null;
        aNode<string> tail = null;

        public void add( aNode<string> node)
        {
            if (headNode == null)
            {
                headNode = node;
                tail = node;
            }
            else
            {
                tail.nextNode = node;
                tail = node;
            }
        }

        public void displayList()
        {
            var displayNode = headNode;
            while ( displayNode.nextNode != null)
            {
                Console.WriteLine( displayNode.stored);
                displayNode = displayNode.nextNode;
            }
            Console.WriteLine(tail.stored);
        }
    }
}






And apart from that a dragon fly flew into me, they make a decent noise when they take off.



 

No comments:

Post a Comment