{ "@context": "https://schema.org", "@type": "Organization", "name": "Brainscape", "url": "https://www.brainscape.com/", "logo": "https://www.brainscape.com/pks/images/cms/public-views/shared/Brainscape-logo-c4e172b280b4616f7fda.svg", "sameAs": [ "https://www.facebook.com/Brainscape", "https://x.com/brainscape", "https://www.linkedin.com/company/brainscape", "https://www.instagram.com/brainscape/", "https://www.tiktok.com/@brainscapeu", "https://www.pinterest.com/brainscape/", "https://www.youtube.com/@BrainscapeNY" ], "contactPoint": { "@type": "ContactPoint", "telephone": "(929) 334-4005", "contactType": "customer service", "availableLanguage": ["English"] }, "founder": { "@type": "Person", "name": "Andrew Cohen" }, "description": "Brainscape’s spaced repetition system is proven to DOUBLE learning results! Find, make, and study flashcards online or in our mobile app. Serious learners only.", "address": { "@type": "PostalAddress", "streetAddress": "159 W 25th St, Ste 517", "addressLocality": "New York", "addressRegion": "NY", "postalCode": "10001", "addressCountry": "USA" } }

Core Design Principles Flashcards

(10 cards)

1
Q

The Single Responsibility Principle (SRP)

A
  • Design classes in such a way that there is ideally only a single reason to change a class
    • Leads to smaller and more cohesive classes
    • Leads to less complex classes
    → Classes that are easier to understand and change
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Functional cohesion

A
  • Group entities* that change for the same reasons
  • Separate entities that change for different reasons
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

encapsulation

A

The act of keeping both the data and the computation
together to limit the number of contact points between different parts of your system
often violated through references that escape

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

advanatages of encapsulation

A
  • Understanding a piece of code in isolation is easier
  • Using a piece of code becomes less error-prone
  • Changing a piece of code less likely breaks something else
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

3 ways in which references can escape (slides)

A
  1. Returning a reference to an external object
  2. Storing an external reference internally
  3. Leaking a reference through a shared structure
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

+/- of immutability

A

+ You can share information without breaking encapsulation
+ You avoid temporal method dependencies (invocation order)
+It leads to thread safety
+ It allows the caching of objects

  • You tend to create more objects
  • Decreased performance efficiency (more garbage collection)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to make objects immutable

A
  • Ensure that all the fields of your class are:
    • Either private and not changed by any instance method
    • Or immutable by default
      • Primitive types or enumerations
      • final
  • Expose internal data consciously
    • Extended interface
    • Return copies
    • Via dedicated design patterns
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Inherent complexity

A

Unavoidable domain complexity

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Accidental complexity

A

Avoidable technical complexity introduced through suboptimal design

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

types of complexity

A

Structural complexity (coupling): The number and strength of relationship between the structures in your program (packages, classes, methods)
reading complexity
data complexity
decision complexity

How well did you know this?
1
Not at all
2
3
4
5
Perfectly