One of the major advantages with Javascript is said to be that it is a prototype based language.
But what does it mean that Javascript is prototype based and why is that an advantage?
...
In a nutshell, the hashCode contract, according to Java's object.hashCode():
The hash code shouldn't change unless something affecting equals() changes
equals() implies hash codes are ==
Let's assume interest primarily in immutable data objects - their information never changes after they're constructed, so #1 is assumed to hold. Th...
So no doubt that building a domain model is something that I think happens best when you approach it as as team. Even going so far as to involve someone who is not technical and a member of the 'business' in the modeling sessions. So much can get done quickly when you put the right people in a room and hammer out things on a whiteboard...
I would like to know if somebody often uses metrics to validate its code/design.
As example, I think I will use:
number of lines per method (< 20)
number of variables per method (< 7)
number of paremeters per method (< 8)
number of methods per class (< 20)
number of field per class (< 20)
inheritance tree depth (< 6).
Lack of Cohesion ...
An idiom commonly used in OO languages like Python and Ruby is instantiating an object and chaining methods that return a reference to the object itself, such as:
s = User.new.login.get_db_data.get_session_data
In PHP, it is possible to replicate this behavior like so:
$u = new User();
$s = $u->login()->get_db_data()->get_session_dat...
What are the best practices for modeling inheritance in databases?
What are the trade-offs (e.g. queriability)?
(I'm most interested in SQL Server and .NET, but I also want to understand how other platforms address this issue.)
...
I'm experiencing what I believe is a circular dependency issue with my PHP application. Please let me know if this is incorrect. Here is the situation:
Two classes, LogManager and DBSession.
DBSession is used to interact with the database, and LogManager is used to log to files. Both are widely used in my application. When you create a...
When are custom Exception classes most-valuable?
Are there cases when they should or should not be used? What are the benefits?
Related questions:
Performace Considerations for throwing Exceptions
Do you write exceptions for specific issues or general exceptions?
...
As far as I can understand, when I new up a Linq to SQL class, it is the equivalent of new'ing up a SqlConnection object.
Suppose I have an object with two methods: Delete() and SubmitChanges(). Would it be wise of me to new up the Linq to SQL class in each of the methods, or would a private variable holding the Linq to SQL class - new'...
I look around and see some great snippets of code for defining rules, validation, business objects (entities) and the like, but I have to admit to having never seen a great and well-written business layer in its entirety.
I'm left knowing what I don't like, but not knowing what a great one is.
Can anyone point out some good OO business...
I need to model a system where by there will be a team who will consist of users who perform roles in the team and have skills assigned to them.
i.e. a team A 5 members, one performs the team leader role, all perform the reply to
email role, but some have an extra skill to answer the phone
I'm trying to determine how I can best model t...
I feel like a fool, but here goes:
public interface IHasErrorController{
ErrorController ErrorController { get; set; }
}
public class DSErrorController: ErrorController{yadi yadi ya}
public class DSWebsiteController : Controller, IHasErrorController{
public DSErrorController ErrorController { get; set; }
}
This gives me an err...
So I understand what a static method or field is, I am just wondering when to use them. That is, when writing code what design lends itself to using static methods and fields.
One common pattern is to use static methods as a static factory, but this could just as easily be done by overloading a constructor. Correct? For example:
var b...
I'm working on a project in C#. The previous programmer didn't know object oriented programming, so most of the code is in huge files (we're talking around 4-5000 lines) spread over tens and sometimes hundreds of methods, but only one class. Refactoring such a project is a huge undertaking, and so I've semi-learned to live with it for no...
Here is an example of polymorphism from http://www.cplusplus.com/doc/tutorial/polymorphism.html (edited for readability):
// abstract base class
#include <iostream>
using namespace std;
class Polygon {
protected:
int width;
int height;
public:
void set_values(int a, int b) { width = a; height = b; }
...
The C++ friend keyword allows a class A to designate class B as it's friend. This allows Class B to access the private/protected members of class A.
I've never read anything as to why this was left out of C# (and VB.NET). Most answers to this earlier StackOverflow question seem to be saying it is a useful part of C++ and there are go...
Let's have the following class hierarchy:
public class ParentClass implements SomeInterface {
}
public class ChildClass extends ParentClass {
}
Then let's have these two instances:
ParentClass parent;
ChildClass child;
Then we have the following TRUE statements
(parent instanceof SomeInterface) == true
(child instanceof SomeInter...
Say I have a class that's meant to perform a single function. After performing the function, it can be destroyed. Is there any reason to prefer one of these approaches?
// Initialize arguments in constructor
MyClass myObject = new MyClass(arg1, arg2, arg3);
myObject.myMethod();
// Pass arguments to method
MyClass myObject = new MyClass...
What are the downsides to using static methods in a web site business layer versus instantiating a class and then calling a method on the class? What are the performance hits either way?
...
As I mention in an earlier question, I'm refactoring a project I'm working on. Right now, everything depends on everything else. Everything is separated into namespaces I created early on, but I don't think my method of separtion was very good. I'm trying to eliminate cases where an object depends on another object in a different namespa...