oop

Is deriving square from rectangle a violation of Liskov's Substitution Principle?

I am new to design and learning the design principles. It says deriving square from rectangle is a classic example of violation of Liskov's Substitution Principle. If that's the case, what should be the correct design? ...

How to avoid lots of parameters in critical methods of my applications?

Hi. I tend to sucessfully write compact applications that can encapsulate many business logic in a simple and non-redundant way. I tend to create small methods, but over time I arrive to methods that have too many parameters. I know every code requires its design, but I see and antipattern in my behaviour and I am not sure which would be...

Subclassing SharePoint Objects

Hi, I want to subclass some SharePoint objects, such as SPSite, SPWeb, SPList, and SPListItem. Any idea how to do it? I cannot create an instance of my derived class since I can't construct the objects with a constructor. I usually used a container class to wrap the said objects, but I don't think it's a good solution since it doesn't ...

Is it ok to downcast?

I'm designing a framework which users can extend. Basically I will provide them a set of interfaces which they can implement, and my "manager" class will call their implementations like this: abstract1 = factory.GetConcreteExtension1() abstract2 = factory.GetConcreteExtension2() abstract1.DoSomething(abstract2) Where my client impleme...

Outer Variable Access in PHP Class

Consider the following situation file: ./include/functions/table-config.php containing: . . $tablePages = 'orweb_pages'; . . file: ./include/classes/uri-resolve.php containing: class URIResolve { . . var $category; . . function process_uri() { ... $this->category = $tablePages; ... } . . } file: ./settings.php containing: . . req...

Using strings to select Object Properties

I'm having a bit of trouble with a C# program I'm writing and it'd be great if someone could help. The background is this, not terribly important, but it's why I need to figure out how to do it: I'm using a database's Web Services to retrieve information about an entry in the database. Each access to the database returns an Object with...

Choose between datatypes and call matching methods?

Here is what I am trying to do: if (a==true) { dbA objectInstance = new dbA(); } else { dbB objectInstance = new dbB(); } objectInstance.Name = "New name"; I get "the name objectInstance does not exist in the current context", I assume because the def happens inside the conditional. There must be a better pattern to do this...

A project that implements a number of the design patterns?

Someone once mentioned to me about a project (or two), maybe written in Java, that they used in school to help teach them design patterns. It implemented a number of the design patterns but was for learning purposes only. I know you should not try to stuff a bunch of the design patterns into a application just for the sake of using the...

What are some advantages to using an interface in C#?

I was forced into a software project at work a few years ago, and was forced to learn C# quickly. My programming background is weak (Classic ASP). I've learned quite a bit over the years, but due to the forced nature of how I learned C#, there are a lot of basic concepts I am unclear on. Specifically, an interface. I understand the b...

Am I writing AS3 the right way?

I'm very new to flash and actionscript 3. I've been reading a lot about it and this is also my first aprouch on object oriented programming. So far, I created an application with a login button, that's all. However, I would like to know what kind of things I am doing wrong or should be doing different (or better). I am using Adobe Flex ...

How do I create a Perl class?

I am writing Perl classes to remove redundancies from scripts and since Perl has a lot of ways to make classes I keep having trouble making the classes properly. So does anyone have a best practice example of a class? The biggest question I have is if there should be no global variables in a module how do you use variables across sub() ...

Can I have object with the same name as class in javascript?

Can I have object with the same name as class in javascript? ...

Should one extend or encapsulate ORM objects?

I'm having trouble understanding how to use ORM generated objects. We're using LLBLGen for mapping our database model to objects. These objects we encapsulate in another layer which represents our business model(I think). Maybe this bit of code will explain this better. public class Book { // The class as used in our application pr...

Recursively printing data structures in Perl

I am currently learning Perl. I have Perl hash that contains references to hashes and arrays. The hashes and arrays may in turn contain references to other hashes/arrays. I wrote a subroutine to parse the hash recursively and print them with proper indentation. Though the routine works as expected, my instructor was not convinced about...

Why is the C++ STL is so heavily based on templates? (and not on *interfaces*)

I mean, aside from its obligating name (the Standard Template Library)... C++ initially intended to present OOP concepts into C. That is: you could tell what a specific entity could and couldn't do (regardless of how it does it) based on its class and class hierarchy. Some compositions of abilities are more difficult to describe in this...

Does "An Introduction to Object-Oriented Programming" by Timothy Budd still have value?

If one has a good understanding of the different principles that make up OOP does the book "An Introduction to Object-Oriented Programming" by Timothy Budd would still have value to read? It's mentioned in a few texts and it sounds like a great book to read when you're starting off but what if you've got a bit of experience under your...

reading a configuration information only once in Python

I'm using the ConfigParser to read the configuration information stored in a file. I'm able to read the content and use it across other modules in the project. I'm not sure if the configuration file is read every time I call config.get(parameters). How can I make sure that the configuration information is read only once and rest of the t...

Does C's FILE have an object-oriented interface?

Does the FILE type used through standard C functions fopen, etc. have an object-oriented interface? I'm looking for opinions with reasoning rather than an absolute answer, as definitions of OO vary by who you ask. What are the important OO concepts it meets or doesn't meet? In response to JustJeff's comment below, I am not asking wheth...

Inheritance Question

I have a base class, "B", which has two constructors, one with no paremeters and the other that accepts one param, an integer I have a subclass, "S", which inherits from "B" and does not define any constructors in it. I create an instance of S, attempting to pass to the constructor an integer. I get the error: Error 1 Too many argume...

How to efficiently save objects to a SQL 2000 database

In the past, whenever my application needed to insert many records into a SQL 2000 db, I would call a stored procedure, once for each record. When inserting many records, I found that performance suffered, particularly when with a fat client, calling a web service to perform the database call. Then I learned that if I passed XML data re...