downcast and upcast

That is correct. When you do that you are casting it it into an employee object, so that means you cannot access anything manager specific. Downcasting is where you take a base class and then try and turn it into a more specific class. This can be accomplished with using is and an explicit cast …

Read more

Factory pattern in C#: How to ensure an object instance can only be created by a factory class?

You can make the constructor private, and the factory a nested type: public class BusinessObject { private BusinessObject(string property) { } public class Factory { public static BusinessObject CreateBusinessObject(string property) { return new BusinessObject(property); } } } This works because nested types have access to the private members of their enclosing types. I know it’s …

Read more

When to implement and extend? [closed]

Inheritance is useful to reduce the amount of code you rewrite. If you have several classes with a few common methods or fields, instead of defining these methods and fields over and over you can factor them into a base class and have each of the child classes extend that base class. Interfaces (and implements) …

Read more

Why all the Active Record hate? [closed]

There’s ActiveRecord the Design Pattern and ActiveRecord the Rails ORM Library, and there’s also a ton of knock-offs for .NET, and other languages. These are all different things. They mostly follow that design pattern, but extend and modify it in many different ways, so before anyone says “ActiveRecord Sucks” it needs to be qualified by …

Read more

The value of “this” within the handler using addEventListener

You can use bind which lets you specify the value that should be used as this for all calls to a given function. var Something = function(element) { this.name=”Something Good”; this.onclick1 = function(event) { console.log(this.name); // undefined, as this is the element }; this.onclick2 = function(event) { console.log(this.name); // ‘Something Good’, as this is the …

Read more