Results 1 to 5 of 5

Thread: Children are singleton

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Children are singleton

    Is this a good choice? Say I can have 20-30 children and can be loaded in an MDI parent form... Is this a good design?

    Thanks in advance.

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Children are singleton

    I wouldn't say so. Why do you need so many child forms, what are you doing? I think if you have that many you need to have a design rethink

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Re: Children are singleton

    Any comments on the singleton thing? "Say I can have..." I suppose I misuse the "can have" but I did say "Say", so not necessarily 20-30.

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Children are singleton

    Singleton? You mean where all the windows are floating? I would say that is even worse if you are going to often have that many windows. On the other hand if you aren't often going to have that many then it could be a better choice. It depends really on things like toolbar placement etc.

    Maybe you should try the MDI Tab control from vbAccelerator:
    http://www.vbaccelerator.com/home/VB...bs/article.asp

    That's assuming your using VB6

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Re: Children are singleton

    Thanks for the link. I guess, I can't use it, I'm with C#. Not really good with it (just staring out) but I guess I can try to learn. Singleton, btw, is a pattern in which only one instance of the class can exists at runtime. It's my choice for now as to dealing with the children to assure only one instance of a certain child can exist. I don't really know if this is good (especially having a large number of children open inside the MDI container).

    Sample code of singleton class is something like

    Code:
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    
    namespace WindowsApplication1
    {
    	/// <summary>
    	/// Summary description for SingletonForm.
    	/// </summary>
    	public class SingletonForm : System.Windows.Forms.Form
    	{
    		/// <summary>
    		/// Required designer variable.
    		/// </summary>
    		private System.ComponentModel.Container components = null;
    
    		private SingletonForm()
    		{
    			//
    			// Required for Windows Form Designer support
    			//
    			InitializeComponent();
    
    			//
    			// TODO: Add any constructor code after InitializeComponent call
    			//
    		}
    
    		/// <summary>
    		/// Clean up any resources being used.
    		/// </summary>
    		protected override void Dispose( bool disposing )
    		{
    //			if( disposing )
    //			{
    //				if(components != null)
    //				{
    //					components.Dispose();
    //				}
    //			}
    //			base.Dispose( disposing );
    		}
    
    		#region Windows Form Designer generated code
    		/// <summary>
    		/// Required method for Designer support - do not modify
    		/// the contents of this method with the code editor.
    		/// </summary>
    		private void InitializeComponent()
    		{
    			this.components = new System.ComponentModel.Container();
    			this.Size = new System.Drawing.Size(300,300);
    			this.Text = "SingletonForm";
    		}
    		#endregion
    
    		static SingletonForm instance=null;
    
    		public static SingletonForm GetInstance()
    		{
    			if(instance==null) instance=new SingletonForm();
    			return instance;
    		}
    	}
    }
    in which we have a member variable of her type (class type) representing it as the instance of the class. Also it's a static to assure it's not a member of the object but to the class itself. Contructor also are made private so no one can have the use of the new operator. Accessing it will then be SingletonForm.GetInstance().AndManipulateHere().

    As I said, I don't really know if this is good enough to have all the child as being a singleton. I need help on suggestions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width