0
votes
2answers
158 views

C# - initialize variable inside method and use in whole class [on hold]

this is a conceptual question, but if i initialize a variable in c# as public will it be able to be used in the class as I want a variable "player1" and a variable "player2" where either could be one ...
1
vote
3answers
139 views

Am I violating LSP if the condition can be checked?

This base class for some shapes I have in my game looks like this. Some of the shapes can be resized, some of them can not. private Shape shape; public virtual void SetSizeOfShape(int ...
0
votes
1answer
81 views

Passing in config values to a method using SOLID principles

I have an email helper class that has a method that sends email: private static class EmailHelper { public static void SendEmail(string from, string to, string subject, string message) { ...
1
vote
3answers
139 views

Extending a struct. Using helper classes rather than composition

I have a struct which I want to add static methods to. Yes, you guessed right I'm talking about Datetime. It's a pretty typical requirement to add MyCustomParse. It happens to return Datetime?, so ...
0
votes
1answer
71 views

Inheriting from Abstract class vs Enum Types for custom exceptions

I am creating an interface and would like the implementer(s) of this interface to throw exceptions in the case that something goes wrong. Let's call the implementer a plugin. I have a director which ...
-3
votes
0answers
84 views

C# Implementing filtered Iterator without using yield return [migrated]

I'm trying to display elements of a list with filter and without filter. Here, I use the filter in such a way to display the elements which are divisible by 3. I'm going to use Enumerable and ...
-2
votes
1answer
154 views

Implementing IEnumerator without using 'yield return' in c#

I'm new to C# programming, I was experimenting with iterators concept in C#. Here, I'm trying to display all the terms in a list, for that I'm trying different ways to obtain the results. In the below ...
2
votes
3answers
346 views

What is a good design for a method that can return several logically different results?

The question title is probably too abstract, so let me provide a particular example of what I have in mind: There is a webservice that encapsulates a process of changing passwords for users of a ...
1
vote
2answers
136 views

Sanity check for design pattern used with an intricate calculation model

I am working on a project that generates technical brochures in batch. The 3rd party API that is being used expects POCOs with property names that match field names used in each of the brochure ...
3
votes
3answers
395 views

Why shouldn't an object reference have access to a static member in C#

Context of my question: I am reading C#. Trying to understand Static keyword. I understand that when Static is applied to a member of a class, it can only be modified by the class and not the class ...
4
votes
3answers
156 views

Is it a good idea to return a default value if a field in a query cannot be found?

At the place I work we are using a SafeReader class that wraps an IDataReader. One of the 'features' is that if the field you are trying to access wasn't in the query then it just returns a default ...
2
votes
2answers
258 views

Project based prefix for class names

My project leader uses project based prefixes for class names, lets say projects name ABC, he create User class name as ABCUser. and he says he do this becasuse if he wants to make User.aspx Users get ...
1
vote
4answers
246 views

Circular dependency and object creation when attempting DDD

I have a domain where an Organization has People. Organization Entity public class Organization { private readonly List<Person> _people = new List<Person>(); public Person ...
2
votes
1answer
197 views

Best practice to collect information from child objects

I'm regularly facing following pattern: public abstract class BaseItem { BaseItem[] children; // ... public void DoSomethingWithStuff() { StuffCollection collection = new ...
0
votes
2answers
243 views

Can an object call a method on it's immediate descendant? [closed]

I have an inheritance hierarchy three deep : an abstract base class, from which I derive another abstract class, call it the intermediate class, from which will derive possibly a large variety of ...
1
vote
2answers
204 views

I'm not sure how to add common functionality to my business objects using DTOs/DDD? [closed]

I have created a couple of projects to create a better division of my code: I have a Portable Class Library targeting all frameworks that contains just basic DTOs (auto-generated against a database). ...
2
votes
2answers
115 views

How to (or should I) have one assert per test with object comparisons? [duplicate]

I've recently read The Art of Unit Testing by Roy Osherove which I found very useful for helping me establish how to define a good unit test. One key aspect of the guidelines Roy puts forward are to ...
0
votes
2answers
132 views

Interface method signature not restrictive enough

I wrote a piece of code at my job sometime ago. While writting the code I wrote few interfaces who would allow me to add more flexibility and at that time I was also trying to understand OOP concept ...
0
votes
0answers
354 views

How to design socks proxy server (OOP)

I'm working on a socks server application written in C#. But I don't really know how to design this in a nice way. I got this for Socks V4 and V4A: I'm not sure if it clears things up, but I think ...
-1
votes
1answer
224 views

How to make C# methods work like javascript functions? [closed]

I'll keep it simple, I want to make C#'s methods work like javascript's functions. Mainly so I can convert this - function makeVariable(terp) { var me = {value: 0}; return function () { ...
3
votes
2answers
364 views

Implementing the Interface Segregation Principle

Does this IConvertible interface satisfy the Interface Segregation Principle (ie. the "I" in SOLID)? Here is the definition: public interface IConvertible { TypeCode GetTypeCode(); bool ...
3
votes
2answers
168 views

Is it an acceptable practice to Get a property, that involve parsing binary, that might throw an exception?

I have a property that is loaded lazily, any time after the ctor is called. It is possible that the binary that my property relies on is invalid. If invalid I might have to throw an exception. ...
2
votes
3answers
572 views

Empty virtual method on base class VS abstract methods

I couldn't find a question that was not too specific to some case, so I'll try to make this very generic. We need an extractor base class to a set of documents, for example. Each document has its ...
2
votes
2answers
238 views

Pattern for multiple datasources

I've already read this question on CodeReview. I was hoping for general advice. I'm writing a service which will go to numerous data sources. Each source requires getting copious amounts of data ...
-4
votes
1answer
143 views

what is the main utility of Interface in real world programming (OOPS) [duplicate]

what is the main utility of Interface. we know that we can implement dynamic behavior using interface but i guess it is not only the utility. so i like to know when we have to write interface and when ...
1
vote
1answer
151 views

When to use Interface variable = new class variable OOP

I saw often people use this code like interface IAnimal { void die(); } class Cat : IAnimal { void die() { ... } void meow() { ... } } IAnimal anAnimal = new Cat(); Cat aCat= new ...
1
vote
1answer
348 views

A class with only methods

What's the name for a class that has only methods? There are no fields/properties. Just two methods with the ability to parse some file in two ways. I have named the class Parser, but it just doesn't ...
2
votes
5answers
415 views

Should I use automatic properties?

I'm new to C# coming from a Java background. I'm working on a take home assignment for a coding interview. I normally write my code as following(Java): public class Test { //fields private ...
1
vote
3answers
280 views

Pattern for costly precondition check before acting

Let's say I have a method DoTheThing() which requires the precondition-check CanTheThingBeDone() to return true. The latter method is time consuming as it accesses the database. I'm finding it hard ...
1
vote
1answer
120 views

Question on Graph

I am trying to implement a graph data structure in C#. I have the following interfaces: public interface IVertex<TValue> { TValue Value { get;} ...
0
votes
1answer
202 views

Need an OOP pattern or strategy for “pluggable” property

I'm using OOP and MVVM in a WPF c# application. The goal is for the resulting object (data-bound to user interface) to accurately represent a product. One specific area of the product is highly ...
0
votes
1answer
127 views

What's a similar functionality in JavaScript that insures the object has X data before any actions are taken?

If java/C#/etc one might do something like create a constructor with a parameter, the parameter being the thing the rest of the object may act upon. How is this done in JavaScript? I'm trying to ...
33
votes
3answers
1k views

Does Java development typically involve more subclassing than C#/.NET?

I've recently started looking at Android development. This has brought me back into the world of Java software development. The last time I worked with Java, I'll admit, I didn't understand OOP nearly ...
1
vote
3answers
297 views

Problems with Facades and then evolution in software

I initially started a project with Facades and Polymorphism as a way to create simple extensible design following SOLID Principles. Here is a sample code: public interface IInterface { void ...
0
votes
4answers
381 views

Problem regarding DRY principle and Polymorphism

I have a class that is 99% identical to its counter part. Sample code goes below: public abstract class BaseClass { void Method1() { } void Method2() { } void Method3() { } public ...
5
votes
1answer
487 views

Dictionary of objects

I have a dictionary of Objects of a class Columns Dictionary<double, Columns> Columns is a class of columns, i.e. name, post code, etc, mobile phone. I would like to make Columns class as ...
4
votes
5answers
550 views

How to model an address type in DDD?

I have an User entity that has a Set of Address where Address is a value object: class User{ ... private Set<Address> addresses; ... public setAddresses(Set<Address> ...
1
vote
3answers
429 views

C# vector class - Interpolation design decision

Currently I'm working on a vector class in C# and now I'm coming to the point, where I've to figure out, how i want to implement the functions for interpolation between two vectors. At first I came up ...
25
votes
3answers
4k views

Rich Domain Models — how, exactly, does behavior fit in?

In the debate of Rich vs. Anemic domain models, the internet is full of philosophical advice but short on authoritative examples. The objective of this question is to find definitive guidelines and ...
0
votes
2answers
549 views

Memory allocation of Classes that don't have any global data and locks

static void Main(string[] args) { var c2 = new Class2(); var c3 = new Class3(); var c1 = new Class1(c2, c3); c1.Method1(); } class Class1 { ...
1
vote
4answers
542 views

How do you evaluate learning C# from videos for a beginner? [closed]

I have an idea about programming in general so I know what a variable and a method is but I didn't program before. I liked C# because of Visual Studio and I only tried Hello word program in it. I ...
1
vote
2answers
166 views

Determining the aggregates in this domain

I'm working on an ordering system where we receive tab delimited files that look like this (I removed most of the columns for clarity): OrderId OrderLineId BuyerName BuyerAdress ...
1
vote
3answers
329 views

Does non-virtual-by-default lead us to composition-over-inheritance?

There are some design guidelines about testable code in “The Art of Unit Testing”. The first one is “Make methods virtual by default”. I’m curious to know your idea about non-virtual-by-default ...
3
votes
1answer
737 views

Cookie access within a HTTP Class

I have a HTTP class that has a Get, and Post, method. It's a simple class I created to encapsulate Post and Get requests so I don't have to repeat the get/post code throughout the application. In C#: ...
25
votes
1answer
2k views

Why is an anemic domain model considered bad in C#/OOP, but very important in F#/FP?

In a blog post on F# for fun and profit, it says: In a functional design, it is very important to separate behavior from data. The data types are simple and "dumb". And then separately, you ...
2
votes
3answers
386 views

Recommened design pattern to handle multiple compression algorithms for a class hierarchy

For all you OOD experts. What would be the recommended way to model the following scenario? I have a certain class hierarchy similar to the following one: class Base { ... } class Derived1 : ...
8
votes
4answers
5k views

Is it a good practice to create a ClassCollection of another Class?

Lets says I have a Carclass: public class Car { public string Engine { get; set; } public string Seat { get; set; } public string Tires { get; set; } } Lets say we're making a system ...
2
votes
1answer
400 views

OOP when using a GUI Designer

I usually do database and web development but at the moment I'm learning desktop development with Mono and Gtk# using using the MonoDevelop IDE. I'm also using the Stetic GUI Designer inside ...
4
votes
7answers
605 views

Naming guard clauses that throw exceptions

I have a function evaluate() that parses a String for some variables and replaces them with their corresponding value: public String evaluate() { String result = templateText; for ...
0
votes
1answer
353 views

How can my code structure be improved? [closed]

I am looking for advice on the neatest way to structure my code. class Password { private string cipher; Password(string cipher) { this.cipher = cipher; } public string ...