Usuário com melhor resposta
ESclarecimento Singleton

Pergunta
-
Boa Noite Colegas!
Preciso de uma ajuda.
Estou tentando aplicar o padrao Singleton em uma calculadora em winform mas, não estou conseguindo por falta de conhecimento.Se alguem puder esclarecer agradeço muito;
Segue o que estou tentando aplicar:
classe form:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace AulaVisual
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
float num1, ans;
int count;
private void btnSair_Click(object sender, EventArgs e)
{
Application.Exit();
}
//1
private void btn1_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 1;
}
//2
private void btn2_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 2;
}
//3
private void btn3_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 3;
}
//4
private void btn4_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 4;
}
//5
private void btn5_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 5;
}
//6
private void btn6_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 6;
}
//7
private void btn7_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 7;
}
//8
private void btn8_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 8;
}
//9
private void btn9_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 9;
}
//0
private void btn0_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 0;
}
// -
private void btnSubtrair_Click(object sender, EventArgs e)
{
if (textBox1.Text != "")
{
num1 = float.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
count = 1;
}
}
// +
private void btnSomar_Click(object sender, EventArgs e)
{
num1 = float.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
count = 2;
}
// *
private void btnMultiplicar_Click(object sender, EventArgs e)
{
num1 = float.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
count = 3;
}
// /
private void btnDividir_Click(object sender, EventArgs e)
{
num1 = float.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
count = 4;
}
// +
private void btnIgual_Click(object sender, EventArgs e)
{
Singleton Calcular = Singleton.getInstance();
Calcular._valor = count;
Singleton.compute(count);
}
// ,
private void btnVirgula_Click(object sender, EventArgs e)
{
int c = textBox1.TextLength;
int flag = 0;
string text = textBox1.Text;
for (int i = 0; i < c; i++)
{ if (text[i].ToString() == ",") { flag = 1; break; } else { flag = 0; } }
if (flag == 0)
{ textBox1.Text = textBox1.Text + ","; }
}
private void btnLimpar_Click(object sender, EventArgs e)
{
if (num1 == 0 && textBox1.TextLength > 0)
{ num1 = 0; textBox1.Clear(); }
else if (num1 > 0 && textBox1.TextLength > 0)
{ textBox1.Clear(); }
}
private void Form1_Load(object sender, EventArgs e)
{
}Classe Singleton:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace AulaVisual
{
public class Singleton : Form1
{
float num1,ans;
int count;
private static Singleton _Instacia;
private static object _Instancia;
public float _valor { get; set; }
private Singleton() { }
public static Singleton getInstance()
{
if (_Instancia == null)
{
_Instancia = new Singleton();
}
return _Instancia;
}
public void compute(int count, float _valor)
{
switch (count)
{
case 1:
ans = num1 - _valor;
_valor = ans;
break;
case 2:
ans = num1 + _valor;
_valor = ans;
break;
case 3:
ans = num1 * _valor;
_valor = ans;
break;
case 4:
ans = num1 / _valor;
_valor = ans;
break;
default:
break;
}
}
internal static void compute(int count)
{
throw new NotImplementedException();
}
}
}
- Editado Antonio Luiz Tadeu sábado, 13 de outubro de 2012 00:44
- Movido Fábio Jr domingo, 14 de outubro de 2012 20:17 Não é dúvida sobre scripts (De:Scripts Administrativos)
Respostas
-
Boa Tarde; Colegas , agradeço a todos; Já resolvi o problema de utilização do padrão Singleton. []'s
- Marcado como Resposta Antonio Luiz Tadeu sábado, 17 de novembro de 2012 16:39
Todas as Respostas
-
Boa Tarde; Colegas , agradeço a todos; Já resolvi o problema de utilização do padrão Singleton. []'s
- Marcado como Resposta Antonio Luiz Tadeu sábado, 17 de novembro de 2012 16:39
-
Antonio,
Este fórum é dedicado a scripts administrativos (geralmente utilizando VBScript, PowerShell, bat, etc...)
Para esta dúvida sua você deveria procurar um fórum de Análise/Engenharia de Software se a duvida for sobre padrões ou VB.Net se a dúvida for sobre a linguagem.
Vou mover para a área de VB.net
Fábio de Paula Junior
-
Olá Fábio,
Creio que seria mais correto mover esta pergunta para o Fórum de C#, já que a dúvida está relacionada à linguagem C# e não a Vb.Net.
Antonio, se for possível coloque a sua solução para que colegas da comunidade se beneficiem da mesma.
Visual Studio 2010(Vb.Net)
- Marcado como Resposta Antonio Luiz Tadeu sábado, 17 de novembro de 2012 14:52
- Não Marcado como Resposta Antonio Luiz Tadeu sábado, 17 de novembro de 2012 14:53
-