Click here to Skip to main content
15,899,025 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I am new to programming. To help me learn, I am doing a project to create a PostIT note application.

I think I need to create two classes, one which is the actual note, then another to store and manage a list of open notes. It's not easy to show but something like this;

Class - Note / Properties - IDnum, xpos, ypos, height, width, titlebar, content
Class - NoteHandler /Properties - Postit list / Methods - CreateNew, Delete, SaveChanges

How do I go about creating the list for the NoteHandler? I am thinking that I create a new Note object, then assign it an ID number which I then store in an array in the NoteHandler. I can then refer to that ID number later on when I need it.

I'm certain though that there is another way of doing this by creating some kind of collection of objects. I do not expect anybody to spend any time training me :) although that would be nice. If you could point me at what I need to research to make it work that would be great.

Thanks in advance.
Posted

Nice to read a question that is seeking guidelines for learning, not just a request for code. You are on-track for a solution because you have already defined a clear and unambiguous object model, which is excellent.

For creating a collection in .NET, you have many choices: your choice is (almost) certainly going to be found in the two .NET libraries:
using System.Collections;
using System.Collections.Generic;
In my humble opinion, the key questions to ask yourself in choosing a Collection type are:

1. is the type of object I will store always the same type ? For this case, the answer would be "yes," I think.

2. does the collection I need have to be IEnumerable, from the beginning, in order for me to use the fancy tools that LINQ provides for all types of operations on collections ? [1]

a. do I need to be able to easily sort the collection objects ?

b. do I need fancy ways to find an object, or objects in the collection, to copy them to other objects, etc. ? [2]

3. given how many objects I need to store, and the cost of storage per item, am I constrained in my choice of collection types by quantity, or constrained by performance aspects of access time, and collection manipulation time ? Note: this type of consideration was much more important several years ago !

4. advanced: considerations of thread safety, communication between threads, or processes, serialization and de-serialization ?

A quick look at some of your choices: ... assuming that 'Note' is the name of your class that 'embodies' the Note object:

in System.Collections:

1. use of an Array or Arraylist:
Note[] NoteArray = new Note[10]; // fixed size, explicitly typed
ArrayList NoteArrayList = new ArrayList(); // dynamic size, untyped
Suggest you study and, possibly, implement the other collection types found in System.Collections: Stack, Queue, SortedList, HashTable.

in System.Collections.Generic: Suggest you start with the basic Generic List, then study and/or implement use of a Generic Dictionary:

1. use of a simple generic collection:
List<Note> GenericNoteList = new List<Note>();
2. use of a dictionary: what if you wanted to quickly access a given Note by a matching string, perhaps the Note title:
Dictionary<string, Note> GenericNoteDictionary = new Dictionary<string, Note>();
And now ... at last ... a sample solution: tested in VS Studio 2010 Pro with .NET FrameWork 4.0 client target only:
// declared in the body of Form1's class definition
private Form2 f2;
private Form3 f3;

private void Form1_Load(object sender, EventArgs e)
{
    // instantiate the two other Forms
    f2 = new Form2();
    f3 = new Form3();

    // assign Form2's button a Click Handler
    // we access the private Form2 Button
    // exposed by a public property which is auto-intialized
    // in Form2's constructor just after the call to
    // InitializeComponent();
    f2.f2Button.Click += new EventHandler(f2Button_Click);

    // same technique for Form3's TextBox
    // exposed by a public Property
    f3.f3TextBox.TextChanged += new EventHandler(f3TextBox_TextChanged);
}
Left for you to implement are the f2Button_Click, and f3TextBox_TextChanged event handlers in Form1, and the implementation in Form2, and Form3, of the necessary public properties and their intialization.

After you get your collection strategy worked out and tested, perhaps consider adding some 'extras' to the Note style: date-time field for each Note ... date created ... date modified, and a choice of colors for the Note text and/or background ?

bon apetit, Bill

... edit #1: minor clean-up of some tags that got scrambled in the code-blocks ...
... edit #2: restore sample code accidentally deleted in edit #1; simplified it a bit ...

[1] yes, you can convert certain collection types to IEnumerable that are not IEnumerable to start with, but there is a "cost" to that conversion.

[2] this may sound a bit "abstract," but it's really practical: for example: in the future, do you want users of your Post-It type application to easily find all the Nodes of a certain color, or created between two dates ? Generic Collections which are IEnumerable make this relatively easy.
 
Share this answer
 
v5
Comments
RaisKazi 4-Aug-11 8:38am    
My 5 for Detailed Explanation.
Jim607 4-Aug-11 8:43am    
Wow, thank you for your time in writing that up for me. I think that my list would have to be dynamic as I do not know how many Notes I need. I am going to have to take some time out to study Generics and Collections.

I started my programming with VB6 so I am trying to learn many new technologies here OOP and .NET and getting my head out of the event driven style coding.

I do have a couple of books but find it difficult to put what they show into an actual program and fully understand it. That's why I like to set myself a challenge and learn the bits I need as I come across the need for them. It is a flawed method of learning for sure but it keeps my interest.

I really appreciate you doing that for me and outlining a path to where I need to get to rather than just suggesting going straight to the most difficult implementation.
RaviRanjanKr 4-Aug-11 9:32am    
My 5+
You can try using a List<Note> collection and use the extension methods to query Note objects from the List.
 
Share this answer
 
Comments
BobJanova 4-Aug-11 7:16am    
Yes, List<Note> will handle most of what the OP wants. If Note is made [Serializable] then you can probably dump it to a file that way, too.
Jim607 4-Aug-11 8:15am    
Thanks for your help. I started searching on the web fro Lists and Collections and I found an article/tutorial creating a simple text based program that manages a pack of cards. This pretty much mirrors what I want to do so the card is like a note and the Deck class is like my NoteHandler Class.

Thanks for your help
RaisKazi 4-Aug-11 8:38am    
My 5!
RaviRanjanKr 4-Aug-11 9:25am    
Nice Answer, My 5+

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900