oop

Side effects in an iterator considered harmful?

I've written my first C# iterator today. Woohoo. Interestingly, it has side effects. My iterator filters out invalid files from a directory and returns a sequence of valid files to process. Wheneve it encounters an invlaid file, it moves it to another directory. I tried implementing it as a LINQ query, but really don't like the fact th...

C++: how to create an array of objects on the stack ?

Consider the following piece of Java code. int N = 10; Object obj[] = new Object[N]; for (int i = 0; i < N; i++) { int capacity = 1000 * i; obj[i] = new ArrayList(capacity); } Because in Java, all objects live on the Heap, the array does not contain the objects themselves, but references to the objects. Also, the array itself ...

best name for object for collection of semantically-related inputs?

I'm writing an HTML form generation library. There's a top-level Form class, and at the bottom there are classes for each type of HTML form input object (Select, Textfield, Radio, etc.). There's a class in between, that holds groupings of 1 or more semantically related input objects. For example, one type of this class could be called '...

How can I force the base constructor to be called in C#?

I have a BasePage class which all other pages derive from: public class BasePage This BasePage has a constructor which contains code which must always run: public BasePage() { // Important code here } I want to force derived classes to call the base constructor, like so: public MyPage : base() { // Page specific code h...

How to write main() in an OOP way?

When I first started programming, I wrote everything in main. But as I learned, I tried to do as little as possible in my main() methods. But where do you decide to give the other Class/Method the responsibility to take over the program from main()? How do you do it? I've seen many ways of doing it, like this: class Main { public st...

Default implementations of Abstract methods

I am dealing with a large codebase that has a lot of classes and a lot of abstract methods on these classes. I am interested in peoples opinions about what I should do in the following situation. If I have a class Parent-A with an abstract method. There will only be 2 children. If Child-B implements AbstractMethodA but Child-B does ...

Conception of inheritance in object-oriented languages

I was discussing multiple inheritance vs. single inheritance with a friend of mine, and discovered that plainly, my conception of Object-Oriented design is completely different than his. I am mostly an Obj-C programmer, so Multiple Inheritance is not something I use daily. He is mostly a C++ programmer under Windows/PSP, so we probably ...

I need to combine several methods without adding some data members. Any ideas?

Lets say I need to write several functions processing some data. These functions are performing a single task - some mathematical calculations. I suppose there is no need to combine them with some data members. Shall I use: a class without data members and declare these functions as static methods so I can use them without creating cl...

Shall I use "virtual" keyword for destructor of base-class which is actually an interface?

I have an abstract base class and derived class: type TInterfaceMethod = class public destructor Destroy; virtual; abstract; procedure Calculate; virtual; abstract; procedure PrepareForWork; virtual; abstract; end; type ConcreteMethod = class(TInterfaceMethod) private matrix: TMinMatrix; public constructor Crea...

Does Functional Programming Replace GoF Design Patterns?

Since I started learning F# and OCaml last year, I've read a huge number of articles which insist that design patterns (especially in Java) are workarounds for the missing features in imperative languages. One article I found makes a fairly strong claim: Most people I've met have read the Design Patterns book by the Gang of Four....

Can I overload operators for my own classes in Delphi?

I faced a little trouble - I do not know if I can define my own operators for my classes. For example: type TMinMatrix = class(TMatrix) private RowAmount: Byte; ColAmount: Byte; Data: DataMatrix; DemVector, SupVector: SupplyDemand; public constructor Create(Rows, Cols: Byte); function GetRow...

Can I hold any data members in abstract base class?

I have an abstract class: type TInterfaceMethod = class abstract public destructor Destroy; virtual; abstract; function GetBasePlan: Word; virtual; abstract; procedure CountBasePlan; virtual; abstract; procedure Calculate; virtual; abstract; procedure PrepareForWork; virtual; abstract; end; ...

Persisting Child Objects when the Parent is incomplete in a web application

I am trying to establish the best practice for handling the creation of child objects when the parent object is incomplete or doesn't yet exist in a web application. I want to handle this in a stateless way so in memory objects are out. For example, say we have a bug tracking application. A Bug has a title and a description (both requi...

Maintaining subclass integrity in a relational database

Let's say I have a table that represents a super class, students. And then I have N tables that represent subclasses of that object (athletes, musicians, etc). How can I express a constraint such that a student must be modeled in one (not more, not less) subclass? Clarifications regarding comments: This is being maintained manually, n...

What is the best way to get config variables into a class in php 5?

This is for my DB class. I am new to OO, been a procedural lad for some time, so I'm still a bit murky. My first idea was using a bunch of setter functions/methods.. but after writing a whole bunch, I thought about using PHP's define function, like so. define('MYSQL_USERNAME', 'jimbo'); Is this an accepted practice? What is the best ...

Development Cost of Procedural Programming vs. OOP?

I come from a fairly strong OO background, the benefits of OOD & OOP are second nature to me, but recently I've found myself in a development shop tied to a procedural programming habits. The implementation language has some OOP features, they are not used in optimal ways. Update: everyone seems to have an opinion about this topic, as ...

Practical OO Design with UML by Mark Priestley

I'm moving to a role that requires UML experience, so before I move to the new position I am doing some of my own reading. I have the book Practical OO Design with UML by Mark Priestley, Published by Mc Graw Hill (It was my university text book). Would you recommend this book as an introduction to UML or do you have an alternative? Tha...

ASP.NET/ADO.NET: Handling many database connections inside a .NET Object?

Hi! We have a .NET object that does a lot of reading/writing with the database. Throughout the life cycle of this object (or the asp page that uses it), it may hit the database with a query/update anywhere from 1 to 10 times. Instead of opening and closing a database connection every time the object needs to hit the database, it simpl...

PHP5 Classes - Can you get a calling class's variables?

Okay, so I'm new to OO and still kinda new to PHP5. I have a class Page that creates an instance of DB, which is named $db. In the __construct() of Page, I create the new $db object and I pull a bunch of config data from a file. Now the DB class has a method _connectToDB() which (attempts) to connect to the database. Is there a way i...

Grady Booch: Hero or heretic?

I've heard from various colleagues that Grady Booch is either the model to follow for all OO thought, or the worst source from which programmers should learn. Who is right? EDIT: To be clear, I am not looking for you to tell me to read. I've done that. I am looking for your opinion, but backed up with evidence! of why you think what you...