How can an object-oriented programmer get his/her head around database-driven programming?

后端 未结 11 924
自闭症患者
自闭症患者 2021-01-31 02:35

I have been programming in C# and Java for a little over a year and have a decent grasp of object oriented programming, but my new side project requires a database-driven model.

11条回答
  •  庸人自扰
    2021-01-31 02:57

    The big question: how can you get your head around it? It just takes practice. You try implementing a database design, run into problems with your design, you refactor and remember for next time what worked and what didn't.

    To answer your specific questions... this is a little bit of opinion thrown in, as in "how I would do it", not taking into account performance needs and such. I always start fully normalized and go from there based on real-world testing:

    Table Event
    EventID
    Title
    StartDateTime
    EndDateTime
    
    Table ShiftEvent
    ShiftEventID
    EventID
    ShiftSpecificProperty1
    
    ...
    
    Table Product
    ProductID
    Name
    
    Table Category
    CategoryID
    Name
    
    Table CategoryProduct
    CategoryID
    ProductID
    

    Also reiterating what Pierre said - an ORM tool like Hibernate makes dealing with the friction between relational structures and OO structures much nicer.

提交回复
热议问题