Abstract Design Pattern implementation

I started learning design patterns a while ago (only covered facade and abstract so far, but am enjoying it). I'm looking to apply the Abstract pattern to a problem I have. The problem is: Supporting various Database systems using one abstract class and a set of methods and properties, which then the underlying concrete classes (inheriting from abstract class) would be implementing.

I have created a DatabaseWrapper abstract class and have create SqlClientData and MSAccessData concrete class that inherit from the DatabaseWrapper.

However, I'm still a bit confused about how the pattern goes as far as implementing these classes on the Client.

Would I do the following?:

DatabaseWrapper sqlClient = new SqlClientData(connectionString);

This is what I saw in an example, but that is not what I'm looking for because I want to encapsulate the concrete classes; I only want the Client to use the abstract class. This is so I can support for more database systems in the future with minimal changes to the Client, and creating a new concrete class for the implementations.

I'm still learning, so there might be a lot of things wrong here. Please tell me how I can encapsulate all the concrete classes, and if there is anything wrong with my approach.

Many Thanks!

PS: I'm very excited to get into software architecture, but still am a beginner, so take it easy on me. :)

Answers


It could look something like this:

DatabaseWrapper dbClient = DBFactory.getInstance(DbType.SQL, connectionString);

Almost all design patters just introduce another layer of indirection and/or abstraction. In this case DBFactory is an abstraction layer that selects an appropriate implementation based on DbType enum.


Well, I think that what you need is the Abstract Factory pattern.

Instead of:

DatabaseWrapper sqlClient = new SqlClientData(connectionString);

Use:

DatabaseWrapper sqlClient = DatabaseWrapper.create(connectionString);

And then encapsulate the creation logic inside the static "create" method.


Need Your Help

jQuery Validator functionality Overriding Issue

javascript jquery jquery-validate

I am trying to override the functionality of 'required' and 'minlength' validators provided by jQuery Validator plugin. Following is my code:

Why is the DataSourceSelectArguments sealed?

asp.net database

Does anybody know the logic behind making DataSourceSelectArguments sealed?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.