oop

Dealing with "global" data structures in an object-oriented world

This is a question with many answers - I am interested in knowing what others consider to be "best practice". Consider the following situation: you have an object-oriented program that contains one or more data structures that are needed by many different classes. How do you make these data structures accessible? You can explicitly pa...

Inject data members to an object

This question is based on another question of mine(thankfully answered). So if in a model I have this: def self.find_extended person = Person.find(:first) complete_name = person.firstname + ', ' + person.lastname return person end How can I inject complete name in the person object so in my controller/view I can access it...

What is the correct term for the documentation that we put just above a method declaration?

I'm writing a whitepaper and realized that I am not sure what the official term is for the kind of internal documentation that we put as a comment block before a declaration of definition. The same thing that eventually becomes JavaDoc member documentation. It's not simply internal documentation, and I'm not sure "header documentation"...

How can I prevent a base constructor from being called by an inheritor in C#?

I've got a (poorly written) base class that I want to wrap in a proxy object. The base class resembles the following: public class BaseClass : SomeOtherBase { public BaseClass() {} public BaseClass(int someValue) {} //...more code, not important here } and, my proxy resembles: public BaseClassProxy : BaseClass { public ...

Does dependency injection break the Law of Demeter

I have been adding dependency injection to my code because it makes by code much easier to Unit test through mocking. However I am requiring objects higher up my call chain to have knowledge of objects further down the call chain. Does this break the Law of Demeter? If so does it matter? for example: a class A has a dependency on an i...

Static and Instance methods with the same name?

I have a class with both a static and a non-static interface in C#. Is it possible to have a static and a non-static method in a class with the same name and signature? I get a compiler error when I try to do this, but for some reason I thought there was a way to do this. Am I wrong or is there no way to have both static and non-static ...

How do you force constructor signatures and static methods?

Sorry in advance if the question is naive... Is there a way of forcing a (child) class to have constructors with particular signatures or particular static methods in C# or Java? You can't obviously use interfaces for this, and I know that it will have a limited usage. One instance in which I do find it useful is when you want to enfor...

What would be the best book to read in order to really 'grok' OOP?

How would you recommend I go about learning about Object Oriented Design/Programming? I prefer to learn based on books first (it's likely a bias of mine based on the assumption that books are edited for quality, which "random" websites would not - discuss in question comments if you wish), so I'm really looking for a couple great beginn...

What is the difference with these two sets of code

What is the difference between these two pieces of code type IInterface1 = interface procedure Proc1; end; IInterface2 = interface procedure Proc2; end; TMyClass = class(TInterfacedObject, IInterface1, IInterface2) protected procedure Proc1; procedure Proc2; end; And the following : type IInterface1 ...

Subclassing a class with private members

One of the really nice things about python is the simplicity with which you can name variables that have the same name as the accessor: self.__value = 1 def value(): return self.__value Is there a simple way of providing access to the private members of a class that I wish to subclass? Often I wish to simply work with the raw dat...

Coupling, Cohesion and the Law of Demeter

The Law of Demeter indicates that you should only speak to objects that you know about directly. That is, do not perform method chaining to talk to other objects. When you do so, you are establishing improper linkages with the intermediary objects, inappropriately coupling your code to other code. That's bad. The solution would be fo...

Database Design Issues with relationships

I'm working on an upgrade for an existing database that was designed without any of the code to implement the design being considered. Now I've hit a brick wall in terms of implementing the database design in code. I'm certain whether its a problem with the design of the database or if I'm simply not seeing the correct solution on how to...

Are nulls in a relational database okay?

There's a school of thought that null values should not be allowed in a relational database. That is, a table's attribute (column) should not allow null values. Coming from a software development background, I really don't understand this. It seems that if null is valid within the context of the attribute, then it should be allowed. This...

What´s your favorite definition/citation of an Object (in general) in OOD? (from a book, a person (Meyer, Booch, Reenskaug, Wirfs-Brock etc..))

There are quite some interesting definitions of what an object in OO is? Please post your favorite definitions and quotes! One of my favorites comes from Trygve Reenskaug: "The object has three properties which makes it a simple, yet powerful module building block: It has state so it can model memory. It has behaviour, so it ...

Is it possible to add data members dynamically in PHP?

I'm wondering if its possible to add new class data members at run-time in PHP? ...

CLOS like object model for PHP

I have returned to php development from Moose and I really miss CLOS like object model for php. Is there some kind of syntaxtic sugar which would allow me to write less code in php when dealing with objects? Just to stress this requirement a bit more. I don't want to write one thing in several places. I can live with part of code being ...

Python object attributes - methodology for access

Hello, Suppose I have a class with some attributes. How is it best (in the Pythonic-OOP) sense to access these attributes ? Just like obj.attr ? Or perhaps write get accessors ? What are the accepted naming styles for such things ? Edit: Can you elaborate on the best-practices of naming attributes with a single or double leading under...

What are some best practices for OpenGL coding (esp. w.r.t. object orientation)?

This semester, I took a course in computer graphics at my University. At the moment, we're starting to get into some of the more advanced stuff like heightmaps, averaging normals, tesselation etc. I come from an object-oriented background, so I'm trying to put everything we do into reusable classes. I've had good success creating a came...

Writing a generic class to handle built-in types

Not too practical maybe, but still interesting. Having some abstract question on matrix multiplication I have quickly implemented a matrix for ints, then tested my assumptions. And here I noticed that just int matrix is not good, if I occasionally want to use it with decimal or double. Of course, I could try just to cast all to double,...

How to properly use Struts ActionForms, Value Objects, and Entities?

I've inherited a large Java app that uses Struts, Spring, and Hibernate. The classes and interfaces I deal with daily are: Struts Actions, Struts ActionForms, Value Objects, Service Interfaces and Implementations, DAO Interfaces and Implementations, and Entities. I'm pretty clear on the how and why of most of these, except I'm unsure abo...