oop

Output of the following code

String s1 = "Amit"; //true String s2 = "Amit"; //true String s3 = new String("abcd"); //true String s4 = new String("abcd"); //false System.out.println(s1.equals(s2)); //true System.out.println((s1==s2)); //true System.out.println(s3.equals(s4)); //false System.out.println((s3==s4)); ...

Getting rid of "static" references in C#

Hello. I've recently begun learning C# but have encountered an annoying problem. Every variable I want available to all functions in my program I have to put a "static" in front of and also every function. What I'd like to know is how to avoid this, if possible? Also, small side question: creating public variables inside functions? Thi...

Progress Bar design patterns?

The application I'm writing performs a length algorithm which usually takes a few minutes to finish. During this time I'd like to show the user a progress bar which indicates how much of the algorithm is done as precisely as possible. The algorithm is divided into several steps, each with its own typical timing. For instance- initia...

OOP question about functions that struck me all of a sudden.

Hello, May be my question is stupid. But i would like to get it cleared. We know that functions are loaded in memory only once and when you create new objects, only instance variables gets created, functions are never created. My question is, say suppose there is server and all clients access a method named createCustomer(). Say suppose ...

MVC design question for forms

Hi, I'm developing an app which has a large amount of related form data to be handled. I'm using a MVC structure and all of the related data is represented in my models, along with the handling of data validation from form submissions. I'm looking for some advice on a good way to approach laying out my controllers - basically I will have...

systematizing error codes for a web app in php?

I'm working on a class-based php web app. I have some places where objects are interacting, and I have certain situations where I'm using error codes to communicate to the end user -- typically when form values are missing or invalid. These are situations where exceptions are unwarranted ( and I'm not sure I could avoid the situations wi...

Can simple JavaScript inheritance be simplified even further?

John Resig (of jQuery fame) provides a concise and elegant way to allow simple JavaScript inheritance. It was so short and sweet, in fact, that it inspired me to attempt to simplify and improve it even further. I've modified Resig's original Class.extend function such that it passes all of his inheritance tests (plus a few more), and al...

How to preallocate an array of class in MATLAB?

I have an array of objects in MATLAB and I've called their constructors in a loop: antsNumber = 5; for counter = 1: antsNumber ant(counter) = TAnt(source, target); end MATLAB warns me to use preallocation to speed up the process. I do know the benefits of preallocation but I don't know how to do that for objects. ...

Clear all class variables between instances

This is probably a stupid question, but what's the best way to clear class variables between instances? I know I could reset each variable individually in the constructor; but is there a way to do this in bulk? Or am I doing something totally wrong that requires a different approach? Thanks for helping ... class User(): def _...

When we know a class become too much ?

I start to learn class in PHP. According to my experience with other language, i can tell class is different then function. So, how we spot if our class start to be too much and too important and how we minimize its impact ? EDIT : The question is more able how to spot pattern of the writing class problem. Personally. I expect an answer...

Is it good to subclass a class only to separate some functional parts?

Suppose we have abstract class A (all examples in C#) public abstract class A { private Foo foo; public A() { } public void DoSomethingUsingFoo() { //stuff } public void DoSomethingElseUsingFoo() { //stuff } //a lot of other stuff... } But we are able to split it into two classes...

Shadows vs Overloads in VB.NET

When we have new in C#, that personally I see only as a workaround to override a property that does not have a virtual/overridable declaration, in VB.NET we have two "concepts" Shadows and Overloads. In which case prefer one to another? ...

Design pattern to use instead of multiple inheritance

Coming from a C++ background, Im used to multiple inheritance. I like the feeling of a shotgun squarely aimed at my foot. Nowadays, I work more in C# and Java, where you can only inherit one baseclass but implement any number of interfaces (did I get the terminology right?). For example, lets consider two classes that implement a common...

avoiding enums as interface identifiers c++ OOP

Hi I'm working on a plugin framework using dynamic loaded shared libraries which is based on Eclipse's (and probally other's) extension-point model. All plugins share similar properties (name, id, version etc) and each plugin could in theory satisfy any extension-point. The actual plugin (ie Dll) handling is managed by another library, ...

What exception to throw when an important parameter/dependency is missing?

Take this method /** * @return List of group IDs the person belongs to * */ public List<String> getGroups() { if (this.getId().equals("")) return null; } I would like to throw exception instead returning null, what's the exception to throw when an important parameter/dependency has not been set? ...

How can I model the data in a multi-language data editor in WPF with MVVM?

Are there any good practices to follow when designing a model/ViewModel to represent data in an app that will view/edit that data in multiple languages? Our top-level class--let's call it Course--contains several collection properties, say Books and TopicsCovered, which each might have a collection property among its data. What kind of...

AS3 - Can I know if a class implements an interface (or is a subclass of another class) ?

With this code function someFunction(classParam:Class):Boolean { // how to know if classParam implements some interface? } i.e. Comparing classParam with IEventDispatcher interface: someFunction(EventDispatcher) // returns true someFunction(Object) // returns false I know it can't be done with is operator. But, is there a way ...

PHP: Proper way of using a PDO database connection in a class

Trying to organize all my code into classes, and I can't get the database queries to work inside a class. I tested it without the class wrapper, and it worked fine. Inside the class = no dice. What about my classes is messing this up? EDIT: The problem is that it won't query the database and return a result. Any result. class ac { ...

Graduating from ASP.Net Webforms anti-patterns

On my current project, I'm stuck in an ASP.Net 2.0 Webforms anti-pattern quagmire. I am aware of the myriad of anti-patterns we're using (huge code-behinds, no separation of concerns, untestable code, and on and on). Now, I'm not interested in rescuing this application from this situation as it's too far gone. Instead, my focus is on ...

What problems do you find with this view on domain-driven design?

I just wrote a long (and messy) blogpost about my view on domain-driven design at present day, with frameworks like spring and hibernate massively in use. I'd ask you to spot any problems with my views on the matter - why this won't work, why it isn't giving the benefits of DDD, why it is not a good idea in general. The blogpost is he...