oop

Do you databind your object fields to your form controls?

Or do you populate your form controls manually by a method? Is either considered a best practice? ...

C/C++ Structure offset

I'm looking for a piece of code that can tell me the offset of a field within a structure without allocating an instance of the structure. IE: given struct mstct { int myfield; int myfield2; }; I could write: mstct thing; printf("offset %lu\n", (unsigned long)(&thing.myfield2 - &thing)); And get "offset 4" for the output. ...

Pitfalls of Object oriented programming

Did you ever feel any downside of using OOP as a developer? Do you think over-usage of OOP concepts could lead to something like over-normalized database structures? Where do you think we should draw a line while applying OOP concepts in our design? Cross-links: What's the point of oop? ...

immutable class should be final?

Hi, It says in this article that "Making a class final because it is immutable is a good reason to do so". I'm a bit puzzled by this....I understand that immutability is a good thing from the POV of thread-safety and simplicity, but it seems that these concerns are somewhat orthogonal to extensibility. So why is immutability a good reas...

Closures in PHP... what, precisely, are they and when would you need to use them?

So I'm programming along in a nice, up to date, object oriented fashion. I regularly make use of the various aspects of OO programming that PHP implements but I am wondering when might I need to use closures. Any experts out there that can shed some light on when it would be useful to implement closures? ...

In what namespace should you put interfaces relative to their implementors?

Specifically, when you create an interface/implementor pair, and there is no overriding organizational concern (such as the interface should go in a different assembly ie, as recommended by the s# architecture) do you have a default way of organizing them in your namespace/naming scheme? This is obviously a more opinion based question b...

Should I be extending this class? (PHP)

I'm creating an ORM in PHP, and I've got a class 'ORM' which basically creates an object corresponding to a database table (I'm aiming for similar to/same functionality as an ActiveRecord pattern.) ORM itself extends 'Database', which sets up the database connection. So, I can call: $c = new Customer(); $c->name = 'John Smith'; $c->sav...

c# downcasting when binding to and interface

Is there a better way of binding a list of base class to a UI other than downcasting e.g: static void Main(string[] args) { List<Animal> list = new List<Animal>(); Pig p = new Pig(5); Dog d = new Dog("/images/dog1.jpg"); list.Add(p); list.Add(d); foreach (Animal a in list) { DoPigStuff(...

How can circular dependencies be avoided when callbacks are used?

How can you avoid circular dependencies when you're designing two classes with a producer/consumer relationship? Here ListenerImpl needs a reference to Broadcaster in order to register/unregister itself, and Broadcaster needs a reference back to the Listeners in order to send messages. This example is in Java but it can apply to any OO l...

How to wire a middle tier of Objects to a data tier consisting of a DataSet?

Howdy, I have a middle tier containing several related objects and a data tier that is using a DataSet with several DataTables and relationships. I want to call a Save method on one of my objects (a parent object) and have its private variable data transformed into a DataRow and added to a DataTable. Some of the private variable data ...

Can a Sequence Diagram realistically capture your logic in the same depth as code?

I use UML Sequence Diagrams all the time, and am familiar with the UML2 notation. But I only ever use them to capture the essence of what I intend to do. In other words the diagram always exists at a level of abstraction above the actual code. Every time I use them to try and describe exactly what I intend to do I end up using so much h...

Should I provide a deep clone when implementing ICloneable?

It is unclear to me from the MSDN documentation if I should provide a deep or a shallow clone when implementing ICloneable. What is the preferred option? ...

What's the common way for OOP Pattern design (Data Access)

Hi, Originally there was the DAL object which my BO's called for info and then passed to UI. Then I started noticing reduced code in UI and there were Controller classes. What's the decent recomendation. I currently structure mine Public Class OrderDAL Private _id Integer Private _order as Order Public Function GetOrder(i...

Isn't resource-oriented really object-oriented?

When you think about it, doesn't the REST paradigm of being resource-oriented boil down to being object-oriented (with constrained functionality, leveraging HTTP as much as possible)? I'm not necessarily saying it's a bad thing, but rather that if they are essentially the same very similar then it becomes much easier to understand REST ...

OO vs. Layered; balancing "OO purity" with getting things done

I believe in OO, but not to the point where inappropriate designs/implementations should be used just to be "OO Compliant". So, how to deal with the Serlvet/EJB/DataContainer layered architecture: Servlets receive requests and call a "business layer" (e.g. session EJBs) The business layer locates DataContainers from the database and m...

Modelling Related Objects

I'm designing an application which deals with two sets of data - Users and Areas. The data is read from files produced by a third party. I have a User class and an Area class, and the data is read into a Users array and an Areas array (or other appropriate memory structure, depending on the technology we go with). Both classes have a ...

Inheriting from protected classes in C+++

Suppose I have the following declaration: class Over1 { protected: class Under1 { }; }; I know that I could do the following: class Over2 : public Over1 { protected: class Under2 : public Under1 { }; }; But is there a way to declare Under2 without Over2? Since you would have to exte...

Polymorphism vs Overriding vs Overloading

In terms of Java, when someone says what is polymorphism. Would overloading or overriding be an acceptable answer? I would seem to think that is a bit more than that. IF you had a abstract base class that defined a method with no implementation, and you defined that method in the sub class is that still overridding? I think overloading...

What is the difference between a method and a function

I am a long-time Applescript user and new shell scripter who wants to learn a more general scripting language like Javascript or Python for performance reasons. I am having trouble getting my head around concepts like object orientation, classes and instantiation. If someone could point me to a pithy explanation of methods vs. functio...

What book/resource would you recommend for learning non-OOP design?

I realized that OOP is the only area where I can produce results I'm satisfied with. To be more specific - mainstream static-typed OOP like C++,C# or Java. May be it is so because I've read enough books and articles on it and because most of my programming experience is in OOP. And may be because OOP is just really good :) Each time I h...