Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class A : ICloneable
- {
- int id;
- string name;
- static Random random = new Random();
- public A(string name) { this.id = random.Next(); this.name = "name #" + this.id; }
- pulbic object Clone() { return new A(id, name); }
- private A(int id, string name) { this.id = id; this.name = name; }
- }
- class Axis
- {
- public string Name { get; }
- public Vector Direction { get; }
- private Axis(string name, Vector direction) { Name = name; Direction = direction; }
- static public readonly Axis X = new Axis("X", new Vector(1, 0, 0);
- static public readonly Axis Y = new Axis("Y", new Vector(0, 1, 0);
- static public readonly Axis Z = new Axis("Z", new Vector(0, 0, 1);
- }
- class Point
- {
- public double X { get; }
- public double Y { get; }
- public double R { get; }
- public double Phi { get; }
- private Point(double x, double y, double r, double phi)
- {
- X = x; Y = y; R = r; Phi = phi;
- }
- public Point FromCartesian(double x, double y)
- {
- double r = Math.Sqrt(x * x + y * y);
- double phi = Math.Atan2(y, x);
- return new Point(x, y, r, phi);
- }
- public Point FromPolar(double r, double phi)
- {
- double x = r * Math.Cos(phi);
- double yx = r * Math.Sin(phi);
- return new Point(x, y, r, phi);
- }
- }
- public class MyClass {
- private static Dictionary<object, MyClass> cache =
- new Dictionary<object, MyClass>();
- private MyClass() {
- }
- public static MyClass GetInstance(object data) {
- MyClass output;
- if (!cache.TryGetValue(data, out output))
- cache.Add(data, output = new MyClass());
- return output;
- }
- }
- public abstract class BaseClass {
- private BaseClass() {
- // здесь какая-то базовая инициализация
- // этот конструктор должен быть вызван из конструкторов дочерних классов
- }
- public class SubClass1 : BaseClass {
- public SubClass1() : base() { }
- }
- public class SubClass2 : BaseClass {
- public SubClass2() : base() { }
- }
- }
Add Comment
Please, Sign In to add comment