oop

Java Spring MVC stateless-to-stateful handover

Although I have tagged this as a java/spring question it can be easily asked of any mvc framework with stateless controllers. I know rails uses simple stateless controllers for instance so perhaps you guys know how to best solve this problem. I can best describe the problem with java/spring mvc which is the implementation - forgive the ...

Is there a way to determine what type a class is an instance of in Java?

Say I have 3 classes like so: class A {} class B extends A {} class C extends A {} Would it then be possible to determine whether a particular object was an instance of A, B, or C? I thought that something like this might work: if (myObject.getClass().isInstance(B.class)) { // do something for B } else (myObject.getClass().isIns...

How granular should you make your Observables/Listenables?

You have a pull-oriented Observable/Listenable which notifies Observers/Listeners when some state changes. The state consists of more than one nugget of data, and some of your Observers/Listeners don't care about the whole state. Do you generally prefer to notify all the Observers/Listeners anyway and allow them to ignore notifications...

What are some good resources for introducing a team of VB6 developers to the Object Oriented paradigm?

The team is familiar with ASP.NET and has been working in VB.NET for several years, but they just haven't made the transition in thinking in terms of objects. In fact, they may be a little intimidated by OOP from brief glimpses they've seen of C++ and unmanaged environments. Work has kept them busy enough that they haven't had time to ...

How such an important principle "OCP" will be the reason of massive code duplication practice?

OCP (Open/Closed Principle) is one of the SOLID principles. Which is says: ”Software Entities should be Open for Extension, but Closed for Modification.” It take me while to understand the above sentence about OCP. And when I start read more about it, I found it make sense and so useful, but in the mean time I noticed it cause duplica...

Questions about OO in PHP continued..

Yesterday I had a few question about OO and classes in PHP here but I have a couple new questions. 1a) In the example snippet below you will see the 3 variables set at the top of the class and then used in a method in the class. Notice how the 3 variable declared in the beginning are not set to anything, so is it required to set/list...

Defensive copy: should it be specified in the Javadoc?

Hi, as far as I understand, getters/setters should always make copies, in order to protect the data. However, for many of my classes, it is safe to have the getter return a reference to the property asked for, so that the following code b = a.getB(); b.setC(someValue); actually changes the state of object a. If I can prove that it is...

Handling security and be decoupled

I am trying to design an application in 3 layers : 1) Data access layer 2) business layer 3) UI I try to keep classes decoupled so on the business layer I have created interfaces for the Data access classes like this : public interface ICountryRepository:IRepository { Country GetCountry(int ID); int CreateCountry(Country ob...

PHP: Destroy an object from within the object?

Is there a way in PHP to destroy an object from within that same object? ...

Accessing variables and methods outside of class definitions

Suppose I have a php file along these lines: <?php function abc() { } $foo = 'bar'; class SomeClass { } ?> Is there anything special I have to do to use abc() and $foo inside SomeClass? I'm thinking along the lines of using global in a function to access variables defined outside the function. (I'm new to OOP in PHP) ...

OOP/PHP5: Calling Class A from Class B - or, Making the horse jump

Say you have two classes, A and B. Is it possible to instantiate both classes once and then let class B call methods in class A, and vice versa? It can be done using double colon (::) ... ... but then the method becomes static - is that a disadvantage? (see example below) Can it be done in other ways? With interfaces? This code shows ...

What are static and dynamic variables / methods in OOP?

I am trying to better understand basic concepts in OOP. What are static and dynamic variables and methods in object-oriented programming? What is, for instance, the difference between using $this vs. double colon (::)? $this ($this->a_method()) Advantages: ?. Disadvantages: ? ... "this" is not self-documenting as in: $this->method_fr...

Hiding Properties in Derived C# Classes

I have four classes which share some arrangement of four properties. I have currently set the base class to be abstract with each property marked as virtual. Then in each of the four derived classes I am overriding the properties which it uses and ignoring the others. The problem is that I can still access all properties in each of the ...

Autoload database class

Hello. Can I avoid instantiate a Db object inside of Names object to access it anyways? Would __autoload work for that? Is there another smart solution? I have following classes (They are conceptual so they won't work if executed): Db { function connect($config) { // connect to data base } function query($query) { ...

Which design pattern?

Hello! I am looking for a couple of patterns or design ideas for implementation in C++ that would allow the following. 1. pool of similar objects objects requested and relinquished by client pool grows when exhausted, does not shrink there will be multiple clients (one pool per client to avoid mutexing) An Object Pool seems most ap...

Are Interfaces in JavaScript necessary?

I suppose this could apply to any dynamic language, but the one I'm using is JavaScript. We have a situation where we're writing a couple of controls in JavaScript that need to expose a Send() function which is then called by the page that hosts the JavaScript. We have an array of objects that have this Send function defined so we iterat...

In C++, how can I implement this OOP concept?

I have two implemented classes: class DCCmd : public DCMessage class DCReply : public DCMessage Both are protocol messages that are sent and received both ways. Now in the protocol implementation I'd need to make a message queue, but with DCMessage being abstract it won't let me do something like this: class DCMsgQueue{ pri...

Designing a better API?

What are the best practices and patterns to be followed for designing APIs? How to achieve implementation hiding the best way (C++/Java)? Designing APIs which are generic in nature? Any reference books/links which guide with neat examples to beginners? ...

"Persistence" in C#. How to store objects between procedures?

I have GUI that allows an user to create and modify a point object. I need to store a list of these points to insert at a specific drawing. Here's how I came up with it: In the form code, I opened a private property List<Points> and I manipulate it directly inside form code. Is this the correct way to handle? Something like: public p...

Proper way for count empty variables

Hi, I use kohana and when you try to fetch data from database it returns class variables(like $user->firstname) as a database data. User table have a 12 columns and i fetch 8 columns but at this point some of columuns maybe empty(like $user->phone). How can i found empty column number ?(Proper way..) Thanks A Lot ...