Refactor
:my
=>
'code'
Codes
Refactorings
Popular
Best
Submit
Spam
Account
Logout
Login
JavaScript doesn't seem to be activated, expect things to be ugly and sloppy!
Learn How to Create Your Own Programming Language
createyourproglang.com
Recent
Working PS3 Jailbreak 3.65 And 3.66
ExtaBit Premium Accounts and Cookies
Steam Wallet Hack - Money Adder & Hack v3
Empires & Allies Hack Cheat Trainer v5.4.1
Eve Onnline 60 Days Time Card Generator v2
Xbox Lve Generator v3
Better way to get content via jQuery $.get()
Free CarTown Blue Points Generator and CarTown Templates
Steam Wallet Hack 2012
Diablo 3 error 37 & error 3006 fix
Popular
XBOX POINTS GENERATOR - MICROSOFT POINTS GENERATOR v1.2012
11 may 2012 premium uploading accounts 100% working
Free Microsoft Points
Free Microsoft Points - Microsoft Points Generator - Xbox Live Codes 2012
Car Town Free Blue Points Hack
Free CarTown Blue Points Generator and CarTown Templates
Free Microsoft Points
Simple Days Purger
Sharecash Downloader Bypass Surveys New 05/2012
PAYPAL REMOVE ACCESS LIMITED ACCOUNT 100% Working
Pastable version of
New to refactoring: is my design good?
<pre class='prettyprint' language='cs'>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; using System.Threading; namespace TIG076_Lab4 { public partial class ThreadForm : Form { private Painter rectanglePainter = null; private Painter squarePainter = null; private Painter circlePainter = null; public ThreadForm() { InitializeComponent(); cmbSize.DataSource = PaintingConstants.multiplierSizes; cmbSize.SelectedIndex = 0; PaintingConstants.sizeMultiplier = Int32.Parse(cmbSize.SelectedValue.ToString()); //Trying to make things more random!! Random r1 = new Random(DateTime.Now.Millisecond * 9); Random r2 = new Random(DateTime.Now.Second * DateTime.Now.Millisecond); Random r3 = new Random(r1.Next(1,70) * r2.Next(33, 80)); rectanglePainter = new RectanglePainter(drawingBoard.CreateGraphics(), r1); squarePainter = new SquarePainter(drawingBoard.CreateGraphics(), r2); circlePainter = new CirclePainter(drawingBoard.CreateGraphics(), r3); } private void btnThread1_Click(object sender, EventArgs e) { if (!rectanglePainter.IsBusy) { rectanglePainter.RunWorkerAsync(); } else { rectanglePainter.StopExecution(); } } private void btnThread2_Click(object sender, EventArgs e) { if (!squarePainter.IsBusy) { squarePainter.RunWorkerAsync(); } else { squarePainter.StopExecution(); } } private void btnThread3_Click(object sender, EventArgs e) { if (!circlePainter.IsBusy) { circlePainter.RunWorkerAsync(); } else { circlePainter.StopExecution(); } } private void cmbSize_SelectedIndexChanged(object sender, EventArgs e) { PaintingConstants.sizeMultiplier = Int32.Parse(cmbSize.SelectedValue.ToString()); } private void btnClear_Click(object sender, EventArgs e) { this.drawingBoard.Invalidate(); } } } //Painter.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using System.ComponentModel; using System.Drawing; using System.Threading; namespace TIG076_Lab4 { public abstract class Painter: BackgroundWorker { protected const int PAINTING_THICKNESS = 2; protected Graphics myGraphics; protected Pen myPen; private Random myRandomizer; protected Boolean isRunning; public Painter(Graphics graphics, Random randomizer) { this.myGraphics = graphics; this.myPen = null; this.myRandomizer = randomizer; this.isRunning = false; this.WorkerSupportsCancellation = true; } protected abstract void DrawShape(Point location); private Point RandomizePoint() { int x = myRandomizer.Next(PaintingConstants.DRAWING_MARGIN, PaintingConstants.DRAWING_WIDTH); int y = myRandomizer.Next(PaintingConstants.DRAWING_MARGIN, PaintingConstants.DRAWING_HEIGHT); return new Point(x, y); } protected override void OnDoWork(DoWorkEventArgs e) { this.isRunning = true; while (this.isRunning) { DrawShape(RandomizePoint()); Thread.Sleep(200); } } public void StopExecution() { this.isRunning = false; } } } //CirclePainter.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Drawing; namespace TIG076_Lab4 { public class CirclePainter : Painter { public const int DIAMETER = 10; public CirclePainter(Graphics graphics, Random randomizer) : base(graphics, randomizer) { this.myPen = new Pen(Color.Green, PAINTING_THICKNESS); } protected override void DrawShape(Point location) { int multipliedDiameter = DIAMETER * PaintingConstants.sizeMultiplier; myGraphics.DrawEllipse(myPen, new Rectangle(location, new Size(multipliedDiameter, multipliedDiameter))); } } } //RectangePainter.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Drawing; namespace TIG076_Lab4 { public class RectanglePainter : Painter { private const int HEIGHT = 10; private const int WIDTH = 16; public RectanglePainter(Graphics graphics, Random randomizer) : base(graphics,randomizer) { this.myPen = new Pen(Color.Blue, PAINTING_THICKNESS); } protected override void DrawShape(Point location) { int multipliedHeight = HEIGHT * PaintingConstants.sizeMultiplier; int multipliedWidth = WIDTH * PaintingConstants.sizeMultiplier; myGraphics.DrawRectangle(myPen, new Rectangle(location, new Size(multipliedWidth, multipliedHeight))); } } } //SquarePainter.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Drawing; namespace TIG076_Lab4 { public class SquarePainter : Painter { private const int SIDE = 10; public SquarePainter(Graphics graphics, Random randomizer) : base(graphics, randomizer) { this.myPen = new Pen(Color.Red, PAINTING_THICKNESS); } protected override void DrawShape(Point location) { int multipliedSide = SIDE * PaintingConstants.sizeMultiplier; myGraphics.DrawRectangle(myPen, new Rectangle(location, new Size(multipliedSide, multipliedSide))); } } } // PaintingConstants.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace TIG076_Lab4 { public class PaintingConstants { public const int DRAWING_MARGIN = 5; public const int DRAWING_HEIGHT = 350; public const int DRAWING_WIDTH = 600; public static int sizeMultiplier; public static int[] multiplierSizes = { 1,2,3,4,5}; public enum TrafficLightState { RED, YELLOW, GREEN } } }</pre> <a href="http://www.refactormycode.com/codes/1288-new-to-refactoring-is-my-design-good" style="color:#fff" title="As seen on RefactorMyCode.com"><img alt="Small_logo" src="http://www.refactormycode.com/images/small_logo.gif" style="border:0" /></a>