oop

PHP __get and Private class variables

Assuming one has an abstract base class "foo" with __get() defined, and a child class "bar" which inherits from foo with a private variable $var, will the parent __get() be called when trying to access the private $var from outside the class? ...

Constraint vs. Validation?

I am working with Windows Forms Databinding, implementing interfaces like IDataErrorInfo. In order for this to work, the domain(or business) object is allowed to be in an invalid state. In fact, the domain object needs to retain the invalid value as the user entered it for IDataErrorInfo to work properly. As long as the object isn't p...

Opensource Object Database?

Is there any open source Object Database available? I would like to have a look at the source code and see how stuffs are implemented. ...

OOP: Designing a menu system

Hello! I am currently trying to create a menu system for a game and cannot arrive at any really sound way to do it. There are several menu screens, each of them non-trivial, so that I would like to keep these as separate classes. The main problem I am having is passing control between these menu screens. I tried building each of the scr...

How to build a PHP form Dynamically with OOP?

How would I go about creating a real world form creation class that I can use to display a new form with fields of different types, as how many fields I want, I can use drop downs and I can do all of this by using OOP? ...

Is it correct to inherit from built-in classes?

Hello, I want to parse an Apache access.log file with a python program in a certain way, and though I am completely new to object-oriented programming, I want to start doing it now. I am going to create a class ApacheAccessLog, and the only thing I can imagine now, it will be doing is 'readline' method. Is it conventionally correct to i...

Encapsulation VS Inheritance - How to use a protected function?

In OOP languages like C# or VB.NET, if I make the properties or functions in a super class protected I can't access then in my Form, They can only be access in my class that inherits from that super class. To access those properties or functions I need to make them public which defeats encapsulation on re-write them in my class which de...

What is more important, testability of code, or adherence to OOP principles?

My teams evolution of TDD includes what appear to be departures from traditional oop. Moving away from classes that are self sufficient We still encapsulate data where appropriate. But in order to mock any helper classes, we usually create some way to externally set them via constructor or mutator. We don't use private methods, ever. ...

Why does Flex let me treat a class as an object

This code is blunderous, as it adds a class to an array and later tries to pull it and manipulate it as if it were an object. private function fail(event:Event):void { var myObj:MyClass; var a:ArrayCollection = new ArrayCollection(); var x:MyClass; var y:MyClass; myObj = new MyClass; a.addItem(myObj); a.addItem(MyClass); // !!B...

Is there any reason not to make a member function virtual?

Is there any real reason not to make a member function virtual in C++? Of course, there's always the performance argument, but that doesn't seem to stick in most situations since the overhead of virtual functions is fairly low. On the other hand, I've been bitten a couple of times with forgetting to make a function virtual that should ...

How do you plan an application's architecture before writing any code?

One thing I struggle with is planning an application's architecture before writing any code. I don't mean gathering requirements to narrow in on what the application needs to do, but rather effectively thinking about a good way to lay out the overall class, data and flow structures, and iterating those thoughts so that I have a credible...

How to save and load different types of objects?

During coding I frequently encounter this situation: I have several objects (ConcreteType1, ConcreteType2, ...) with the same base type AbstractType, which has abstract methods save and load . Each object can (and has to) save some specific kind of data, by overriding the save method. I have a list of AbstractType objects which contai...

Best way to learn .NET/OOP best practices?

I'm relatively new to .NET programming (and OOP in general) and I want to make sure I'm not developing bad beginner habits when designing my applications. If you were hiring a new .NET developer and had to get him up to speed relatively quickly, but also wanted to make sure he adopts best practices (e.g., single responsibility principle...

Default properties in VB.Net?

In the early days of .Net, I believe there was an attribute you could decorate a class with to specify a default property. According to some articles I've found, this appears to have been yanked from the framework at some point because it was a little confusing, and I can see how that is the case. Still, is there another way to get th...

Fluent Interfaces - Method Chaining

Method chaining is the only way i know to build fluent interfaces. Here's an example in C#: John = new JohnBuilder().AddSmartCode("c#").WithfluentInterface("Please").ButHow("Dunno"); Assert.IsNotNull(john); [Test] public void Should_Assign_Due_Date_With_7DayTermsVia_Invoice_Builder() { DateTime now = DateTime.Now; ...

Is there a fast way to transfer all the variables of one identical object into another in C#?

This is probably a simple question. Suppose I have a object called Users and it contains a lot of protected variables. Inside that Users class I have a method that creates a temporary Users object, does something with it, and if successful, transfers all the variables from the temp Users object into the one I have. Is there some fa...

How much work should be done in a constructor?

Should operations that could take some time be performed in a constructor or should the object be constructed and then initialised later. For example when constructing an object that represents a directory structure should the population of the object and its children be done in the constructor. Clearly, a directory can contain director...

How do you call a constructor for global objects, for arrays of objects, and for objects inside classes/structs?

How would you call the constructor of the following class in these three situations: Global objects, arrays of objects, and objects contained in another class/struct? The class with the constructor (used in all three examples): class Foo { public: Foo(int a) { b = a; } private: int b; }; And here are my attem...

What is a partial class?

What is and how can it be used in C#. Can you use the same concept in Python/Perl? ...

Good name for an class that holds a object with an onset time

I'm creating a (Java) class to represent an object in a musical score that has a specific onset time, and possibly a duration as well. I need a good name for this class. Is something like "Timed" or "TimedObject" appropriate? I've tried to come up with something that ends in "-able" (like Runnable) but I can't think of anything good; ...