New answers tagged

0

Here's an example that I'm doing to Fake the Id property of my entity. A.CallTo(() => _fakeRepository.FindAll()).Returns((new List<HighSchoolType>()).AsQueryable()); Guid fakePublicHighSchoolId = Guid.NewGuid(); var fakePublicHighSchool = A.Fake<HighSchoolType>(); A.CallTo(() => fakePublicHighSchool.Id)....


3

Why nested classes ? Bjarne Stroustrup explains in "The design and evolution of C++", the origin and rationale behind nested classes: original C++ in 1984 had a single name space (page 5 and 102). the use of nested classes was a compromise between the the concept of a class as a scope and the need of compatibility with C (page 102) it was further ...


0

If class Foo has a private member, such as public class Foo { private int _bar; } Then _bar is accessible from within any instance of Foo. public class Foo { private int _bar; public bool MatchesOtherFoo(Foo other) { return _bar == other._bar; } } You couldn't access _bar from another class, but you can access it from other ...


2

Preface For any given project, the answer to this question will likely differ. This is simply a result of structure and overall philosophy. It may be easy and straightforward in some instances, but extremely difficult and complicated in others. However, if this is a difficult problem, that is a very strong code smell: something is likely quite wrong with ...


0

Are there any more options I should consider? have a look at php constants instead of global variables consider using bit fields instead of a SYSTEM variable or constant


4

Consider these classes: class A { private int foo; public A(int f) { this.foo = f; } // works public int AddTo(A other) { return this.foo + other.foo; } // doesn't work: 'B.bar' is inaccessible due to its protection level public int AddTo(B other) { return this.foo + other.bar; } } class B { public B(int b) { this.bar = b;...


1

Is returning a private pointer is a bad idea ? By making a member private, you express that this is the class internal business, and that you want to ave the freedom to manage such interals as you want. The problem when returning a private pointer, you give your control away, breaking your own design intention: What happens if the caller deletes the ...


0

As stated by others, private variables are good to avoid miss-usages leading the object into an inconsistent status and hard to track bugs and unforeseen exceptions. But in the other hand, what has been mostly ignored by the others is about protected fields. An extended sub-class will have full access to protected fields, making the object as fragile as if ...



Top 50 recent answers are included