Guest User

Untitled

a guest
Nov 19th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. class A : ICloneable
  2. {
  3. int id;
  4. string name;
  5. static Random random = new Random();
  6. public A(string name) { this.id = random.Next(); this.name = "name #" + this.id; }
  7. pulbic object Clone() { return new A(id, name); }
  8. private A(int id, string name) { this.id = id; this.name = name; }
  9. }
  10.  
  11. class Axis
  12. {
  13. public string Name { get; }
  14. public Vector Direction { get; }
  15. private Axis(string name, Vector direction) { Name = name; Direction = direction; }
  16. static public readonly Axis X = new Axis("X", new Vector(1, 0, 0);
  17. static public readonly Axis Y = new Axis("Y", new Vector(0, 1, 0);
  18. static public readonly Axis Z = new Axis("Z", new Vector(0, 0, 1);
  19. }
  20.  
  21. class Point
  22. {
  23. public double X { get; }
  24. public double Y { get; }
  25. public double R { get; }
  26. public double Phi { get; }
  27. private Point(double x, double y, double r, double phi)
  28. {
  29. X = x; Y = y; R = r; Phi = phi;
  30. }
  31. public Point FromCartesian(double x, double y)
  32. {
  33. double r = Math.Sqrt(x * x + y * y);
  34. double phi = Math.Atan2(y, x);
  35. return new Point(x, y, r, phi);
  36. }
  37. public Point FromPolar(double r, double phi)
  38. {
  39. double x = r * Math.Cos(phi);
  40. double yx = r * Math.Sin(phi);
  41. return new Point(x, y, r, phi);
  42. }
  43. }
  44.  
  45. public class MyClass {
  46. private static Dictionary<object, MyClass> cache =
  47. new Dictionary<object, MyClass>();
  48.  
  49. private MyClass() {
  50. }
  51.  
  52. public static MyClass GetInstance(object data) {
  53. MyClass output;
  54.  
  55. if (!cache.TryGetValue(data, out output))
  56. cache.Add(data, output = new MyClass());
  57.  
  58. return output;
  59. }
  60. }
  61.  
  62. public abstract class BaseClass {
  63. private BaseClass() {
  64. // здесь какая-то базовая инициализация
  65. // этот конструктор должен быть вызван из конструкторов дочерних классов
  66. }
  67.  
  68. public class SubClass1 : BaseClass {
  69. public SubClass1() : base() { }
  70. }
  71.  
  72. public class SubClass2 : BaseClass {
  73. public SubClass2() : base() { }
  74. }
  75. }
Add Comment
Please, Sign In to add comment