.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

How to design a class for product searching

Posted By:      Posted Date: October 21, 2010    Points: 0   Category :ASP.Net

Hello, I'm refactoring an old website that has product search code littered throught the codebehind. I'm trying to encapsulate the search logic into its own class so I've created a Product class with a Search() method. I would like some suggestions about OO best practices so that the class is reusable and maintainable. The questions I have are:

- Should I make the search() method an instance method or make it static? For now the class is just really there to encapsulate my search logic 

- If I make it an instance method should it return a list of products or should it populate a member property that I can access like p.Search(); var x = p.ProductList;

- The search method requires upward of 7 parameters of different types, what's the best way to provide them?
    - pass them all i.e. p.Search (param1, param2, ..., param7)
    - create a SearchParams structure in the class, populate it and pass that i.e. p.Search(searchParams)
    - Instantiate a Product object and set properties on it that are used by the Search method i.e.  p.ID = 123; etc.... p.Search();

I've used variations of the above before but would like to know what's the best way.



View Complete Post

More Related Resource Links

Design Question - Child Class Reference


There has to be a better way to design the following:

public class Member {
  public int stateID {get; set;}

  public State state {
    get {
      if (this.stateID > 0) 
        state = State.GetByID(this.stateID);

public class State {
  public string name {get; set; }

  public static State GetByID(int id) {
    //populates state from db

Now if I loop through a list of members and need to display the state name for each member and I call "myMember.State.name" - I'll get the name of the state but it costs me an extra query everytime I call that - even though some of the states may be the same.

Is there a way somehow keep some sort of cache of state name from the db for access?


Class Design Question



I have a question about class design. Currently I am working with following tables:

| Forms
| FormID (PK)
| CommitmentID (FK)
| ...

| Commitments
| CommitmentID (PK)
| CommitDesc
| ...

| Pricings
| PricingID (PK)
| Desc
| CommitmentID (FK)
| ...

| PricingTiers
| TierID (PK)
| PricingID (FK)
| Desc
| ...

Forms <-one to one-> Commitment
Commitment <-one to many-> Pricing
Pricing <-one to many-> PricingTiers

When designing the classes what would be considered a best practice ... for instance at the moment I have 4 classes "Form", "Commitment", "Pricing", and "PricingTier" respectively.

Form class has a public property Commitment which represents an instance of the Commitment class.

Commitment class has a public property List<Pricing> which represents the one to many (Commitment - Pricing) relat

Help with Class Design


This might be the wrong forum, any help is appreciated. So I have an application that allows admins to add types such as document types and training types that are in seperate tables with a foreign key in a transaction table.

When structuring my class I decided to go with an abstract-like pattern (without the factory methods though). So I have a Type abstract class that defines my Save, Delete, and GetList methods. I have a training type class that inherits this class. The thing is all types have 3 main properties - defined in the abstract base - but have different source tables and thus different store procedures in my DbCommand object. So basically I repeat setting up the same parameters on all the derived classes. I would like to implement the common stuff in the base but I am getting thrown off by the difference in data sources.

Thanks in advance!

Question on WorkflowApplication class design ( Func Properties)





I found out that the Workflow Application class offers Func<T> properties to inject code for example when a error occurs.

whats the reason behind the Design Decission of giving the WorkFlow Foundation class Func<T> properties instead of event?


For Example


 Func<WorkflowApplicationUnhandledExceptionEventArgs, UnhandledExceptionAction> OnUnhandledException { get

; set

; }





 Action<WorkflowApplicationCompletedEventArgs> Completed { get

; set

; }


Is it just to prevent the multiple receipients ?

Or is it related to memory mangement due to fix pins caused by eventhandlers ? To be honest i must confess that i'm not sure wether Func<T> will created a fix pin in memory :-(

I'm not sure about if this is good or not, but it would be very nice to get knowledge of the reason why this class is event

Towards a slightly better class design


Hello peeps,

Context: Windows Forms, C# and (slightly better class) design.

I'm an unseasoned programmer. Currently, buidling up a form is not a big deal issue yet. However, programming the object oriented way is. I consider myself confident having basic knowledge  about inherritance, aggregation, overriding, interfaces and abstract classes. But putting the pieces together is something I can't do yet. Here is a small example of what I currently have and then I'll explain what I want to achieve.

This I have in the Form1 class which the IDE generated for me:

  private void dgvIRB_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
   //1. Color cells red if unwanted character(s) are found in a cell
   string unwantedCharacters = "\";][:\\|/!@#$%^&*()+=";
   if (e.Value != null)
    if (e.Value.ToString().IndexOfAny(unwantedCharacters.ToCharArray()) >= 0)
     e.CellStyle.BackColor = Color.Red;
I don't want these kind of details in the form class. There are going to be tons of these rules. So I want to have a dedicated class checking for all these rules which will trigger the coloring of cells, columns and/or rows if something

Abstract Factory Design in C# , Vb.NET

Provide an interface for creating families of related or dependent objects without specifying their concrete classes

Prototype Design Pattern in C#. Vb.NET

Specify the kind of objects to create using a prototypical instance, and create new objects by copying this prototype

Adapter Design Pattern in C#, VB.NET

Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.

Singleton Design Pattern in C#, Vb.NET

Ensure a class has only one instance and provide a global point of access to it.

Class Diagrams

Class diagrams show the static structure of the systems. Classes define the properties of the objects which belong to them. These include:

Attributes - (second container) the data properties of the classes including type, default value and constraints.

Creating a Simple Class in C#

The second article in the C# Object-Oriented Programming tutorial describes how classes are created in C# and how behaviour, in the form of publicly visible and private, hidden methods can be added. This demonstrates some of the uses of encapsulation

Static Class for Beginners

In general, the members of a class can be accessed by instance of that class when they are in public, but there comes a situation to access or call members of a class without an instance and this can be achieved by declaring them as static

Solidify Your C# Application Architecture with Design Patterns

design pattern can solve many problems by providing a framework for building an application. Design patterns, which make the design process cleaner and more efficient, are especially well-suited for use in C# development because it is an object-oriented language. Existing design patterns make good templates for your objects, allowing you to build software faster. This article describes several popular design patterns you can use in your own applications, including the singleton, the decorator, the composite, and the state classes, which can improve the extensibility of your applications and the reuse of your objects.

What Are Design Patterns and Do I Need Them?

Software professionals may be familiar with the term "Design Patterns," but many have no idea of where they come from and what they truly are. Consequently, some do not see the value and benefits design patterns bring to the software development process, especially in the areas of maintenance and code reuse.

Design Patterns for .NET

It is not the intent of the Design Pattern Series to focus on providing a theoretical knowledge dump of all there is to know about design patterns. There are many books that do that already. Instead, this series will focus on providing lots of practical examples. However, there will be some theory to help address important points concerning design patterns. I use the theory of design patterns mostly as a guide and instead make references to good design pattern books for more detail explanation.

Singleton Design Pattern in Asp.net using C#

When we want to make a only one instance of a class and also making sure that there is a global access point to that object then the design pattern we user is called Singleton. The pattern ensures that the class is instantiated only once and that all requests are directed to that one and only object.

The Factory Design Pattern

Software architects generally think in terms of high-level abstractions rather than low-level programming details. Representing a system in terms of high-level abstractions promotes understanding of the system and reduces its perceived complexity. One such set of abstractions is software design patterns. They have been successfully applied in the past to simplify and solve recurring problems in software design.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend