Good Namespace Naming Conventions

后端 未结 7 610
情话喂你
情话喂你 2021-01-14 06:00

I am creating a class library for a CRUD business application. The major \"categories\" of business objects (with related data access layer objects) are:

  • Maint
相关标签:
7条回答
  • 2021-01-14 06:24

    Your namespace hierarchy looks similar to a condition called nested generalization. This is when you have classes which derive multiple different ways.

    Imagine a class hierarchy as follows:

    class Vehicle 
    
    class Car : Vehicle
    class CarRed : Car 
    class CarBlue : Car 
    
    class Truck : Vehicle 
    class TruckRed : Truck 
    class TruckBlue : Truck
    

    Note that vehicles can be either cars or trucks. Also, vehicles can be either red or blue. This works perfectly well, but there is a problem when you want to add a new color, or vehicle type, because the burden of modification grows quadratically.

    This problem is described by the GOF design patterns book -- Specifically the Bridge pattern.

    Although it doesn't specifically address the concerns about namespaces, my instinct tells me that the situations are similar. I would say, if you can avoid this, then you should.

    0 讨论(0)
提交回复
热议问题