SlideShare ist ein Scribd-Unternehmen logo
1 von 26
programming
    basics
    basics

Ladislav Martincik
Content
   - Simple question
   - Complexity OF MODELING
     reality (Not-reality)
   - OOP
   - Coupling (Connascence)
   - big applouse ;)

ALL the time discussion please!
Why oop?
class Component
  attr_accessor :name, :price

  def initialize name, price
    @name = name
    @price = price
  end

  def to_s
    "#{name}: $#{price}"
  end
end
What is better?
def pay(from, to, amount, rounding = 0.5)
  ....
end


def pay(transaction)
  ....
end
Holy OOP

   Keep “large”* software projects
   manageable by human
   programmers.




* what is LARGE?
Real Programming

   HUMAN to HUMAN **

   Complexity our brain can
   handle 4/+-2



** This is one of the reasons why we have high-level
programming languages and not assembler.
REal OOP
Modeling based on Real world experience and
Mathematics

- Modularization- Abstraction -- Understandability
- Encapsulation -- Information Hiding-
Composability -- Structured Design- Hierarchy-
Continuity
Modularization




 Decompose problem into smaller subproblems
 that can be solved separately.
Modularization
 class Component
   include PrintableComponent
   attr_reader :name, :price
   ...
 end

 module PrintableComponent
   def to_s
     "#{name}: $#{price}"
   end
 end
Abstraction --
Understandability



 Terminology of the problem domain is reflected
 in the software solution. Individual modules are
 understandable by human readers.
Abstraction --
Understandability
 set :environment, :development
 set :user, :deploy

 desc "Deploy to production"
 task :deploy do
   scp :local, "deploy@#{server}/#{root_dir}"
 end
Composability --
Structured Design



 Interfaces allow to freely combine modules to
 produce new systems.
Composability --
Structured Design
  gem "bundler"

  plugins

  module Namespace
    module Namespace2
      class X; end
      class Y < X; end
    end
  end
Hierarchy

 class Component
   attr_reader :sub_components
 end

 class Car < Component
   def initialize(color, type)
     @sub_components << Wheel.new('left top')
     @sub_components << Door.new('left driver')
   end
 end
Continuity




 Changes and maintenance in
 only a few modules does not affect
 the architecture.
Continuity
 DRY - Do not repeat yourself
 Coupling - ConNascence
ConNascence

Two software components are connascent if a
change in one would require the other to be
modified in order to maintain the overall
correctness of the system. Connascence is a
way to characterize and reason about certain
types of complexity in software systems.
ConNascence
Strength - The stronger the form of connascence, the more difficult,
and costly, it is to change the elements in the relationship.
Name < Type < Meaning < Position < ...
Degree - The acceptability of connascence is related to the degree
of its occurrence.def fun1(x1, x2) < def fun1(x1, x2, x3, x4, ...)
Locality - Stronger forms of connascence are acceptable if the
elements involved are closely related.
 - Stronger forms of connascence are acceptable if the elements
involved are closely related.
 - Stronger forms of connascence are acceptable if the elements
involved are closely related.
 - Stronger forms of connascence are acceptable if the elements
involved are closely related.
 - Stronger forms of connascence are acceptable if the elements
involved are closely related.
C of Name
 def pay(from, to, amount, correction)
   transaction do
     from.move(to, amount, correction)
   end
 end
C of TYPE
    def pay(transaction)
      if transaction.kind_of? Array

                                      DUCK TYPING
        transaction.each do |t|
          t.run
        end
      else
        transaction.run               def pay(transaction)
      end                               if transaction.respond_to :each
    end                                   transaction.each do |t|
                                             t.run
                                          end
                                        else
                                          transaction.run
                                        end
def pay(transaction)                  end
  Array(transaction).each do |x|
    x.run
  end
end
C of MEANING
class Role
  def can_access_admin?(role_id = 0)
    if role_id == 1     # Admin
      true
    elsif role_id == 2 # Ambassador
      true
    else
      false
    end                         class Role
  end                             ADMIN = 1; AMBASSADOR = 2
end                               def can_access_admin?(role_id = 0)
                                    if role_id == ADMIN
                                      true
                                    elsif role_id == AMBASSADOR
                                      true
                                    else
                                      false
                                    end
                                  end
                                end
C of Position
def pay(from, to, amount, correction)
  ....
end

def pay(options = {})
  ....
end



                        def pay(from, to, options = {})
                          ...
                        end
C of Algorithm
 class User
   def self.encrypt_password
     Digest::SHA1.hexdigest(password)
   end
 end

 class User
   attr_writer :encryption

   def initialize
     encryption = Digest::SHA1.hexdigest
   end

   def self.encrypt_password
     encryption.call password
   end
 end
Conclusion


  Name < Type < Meaning < Position < ALGORITHM
   Name < Type < Meaning < Position < ALGORITHM
Thank you


 Questions? Opinions?

 ladislav.martincik@gmail.com
 martincik.com
            martincik.com
OOP - NEXT time
- Single responsibility principle
- Open/closed principle
- Liskov substitution principle
- Interface segregation principle
- Dependency inversion principle

Weitere ähnliche Inhalte

Was ist angesagt?

C C++ tutorial for beginners- tibacademy.in
C C++ tutorial for beginners- tibacademy.inC C++ tutorial for beginners- tibacademy.in
C C++ tutorial for beginners- tibacademy.inTIB Academy
 
Concept of scoping in programming languages
Concept of scoping in programming languagesConcept of scoping in programming languages
Concept of scoping in programming languagesMd. Jafar Sadik
 
Powerpoint presentation final requirement in fnd prg
Powerpoint presentation final requirement in fnd prgPowerpoint presentation final requirement in fnd prg
Powerpoint presentation final requirement in fnd prgalyssa-castro2326
 
Swift Programming
Swift ProgrammingSwift Programming
Swift ProgrammingCodemotion
 
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...Mark Simon
 
Final requirement in programming niperos
Final requirement in programming   niperosFinal requirement in programming   niperos
Final requirement in programming niperosmarkings17
 
Final requirement in programming vinson
Final requirement in programming  vinsonFinal requirement in programming  vinson
Final requirement in programming vinsonmonstergeorge
 
Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)heoff
 
Kuliah komputer pemrograman
Kuliah  komputer pemrogramanKuliah  komputer pemrograman
Kuliah komputer pemrogramanhardryu
 
Intorudction into VBScript
Intorudction into VBScriptIntorudction into VBScript
Intorudction into VBScriptVitaliy Ganzha
 
Flow of control by deepak lakhlan
Flow of control by deepak lakhlanFlow of control by deepak lakhlan
Flow of control by deepak lakhlanDeepak Lakhlan
 
Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++amber chaudary
 

Was ist angesagt? (19)

C C++ tutorial for beginners- tibacademy.in
C C++ tutorial for beginners- tibacademy.inC C++ tutorial for beginners- tibacademy.in
C C++ tutorial for beginners- tibacademy.in
 
Concept of scoping in programming languages
Concept of scoping in programming languagesConcept of scoping in programming languages
Concept of scoping in programming languages
 
Powerpoint presentation final requirement in fnd prg
Powerpoint presentation final requirement in fnd prgPowerpoint presentation final requirement in fnd prg
Powerpoint presentation final requirement in fnd prg
 
Flow of Control
Flow of ControlFlow of Control
Flow of Control
 
Swift Programming
Swift ProgrammingSwift Programming
Swift Programming
 
VB Script
VB ScriptVB Script
VB Script
 
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
 
Final requirement in programming niperos
Final requirement in programming   niperosFinal requirement in programming   niperos
Final requirement in programming niperos
 
Monad Fact #6
Monad Fact #6Monad Fact #6
Monad Fact #6
 
Final requirement in programming vinson
Final requirement in programming  vinsonFinal requirement in programming  vinson
Final requirement in programming vinson
 
Vb script
Vb scriptVb script
Vb script
 
Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)
 
C++ STATEMENTS
C++ STATEMENTS C++ STATEMENTS
C++ STATEMENTS
 
Vb script tutorial
Vb script tutorialVb script tutorial
Vb script tutorial
 
Kuliah komputer pemrograman
Kuliah  komputer pemrogramanKuliah  komputer pemrograman
Kuliah komputer pemrograman
 
C++ Chapter II
C++ Chapter IIC++ Chapter II
C++ Chapter II
 
Intorudction into VBScript
Intorudction into VBScriptIntorudction into VBScript
Intorudction into VBScript
 
Flow of control by deepak lakhlan
Flow of control by deepak lakhlanFlow of control by deepak lakhlan
Flow of control by deepak lakhlan
 
Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++
 

Andere mochten auch

Andere mochten auch (11)

Object Oriented Programming Basics
Object Oriented Programming BasicsObject Oriented Programming Basics
Object Oriented Programming Basics
 
Programming Basics
Programming BasicsProgramming Basics
Programming Basics
 
Super team
Super teamSuper team
Super team
 
Programming SOLID
Programming SOLIDProgramming SOLID
Programming SOLID
 
People Pattern Power
People Pattern PowerPeople Pattern Power
People Pattern Power
 
Efektivní učení
Efektivní učeníEfektivní učení
Efektivní učení
 
Super kariera
Super karieraSuper kariera
Super kariera
 
SOLID Principles of Refactoring Presentation - Inland Empire User Group
SOLID Principles of Refactoring Presentation - Inland Empire User GroupSOLID Principles of Refactoring Presentation - Inland Empire User Group
SOLID Principles of Refactoring Presentation - Inland Empire User Group
 
The Basics of programming
The Basics of programmingThe Basics of programming
The Basics of programming
 
C programming basics
C  programming basicsC  programming basics
C programming basics
 
Creating HTML Pages
Creating HTML PagesCreating HTML Pages
Creating HTML Pages
 

Ähnlich wie Programming basics and object-oriented principles

name name2 n
name name2 nname name2 n
name name2 ncallroom
 
name name2 n
name name2 nname name2 n
name name2 ncallroom
 
name name2 n2.ppt
name name2 n2.pptname name2 n2.ppt
name name2 n2.pptcallroom
 
Ruby for Perl Programmers
Ruby for Perl ProgrammersRuby for Perl Programmers
Ruby for Perl Programmersamiable_indian
 
name name2 n2
name name2 n2name name2 n2
name name2 n2callroom
 
name name2 n
name name2 nname name2 n
name name2 ncallroom
 
Advanced Internationalization with Rails
Advanced Internationalization with RailsAdvanced Internationalization with Rails
Advanced Internationalization with RailsClinton Dreisbach
 
Pydiomatic
PydiomaticPydiomatic
Pydiomaticrik0
 
Recursion vs. Iteration: Code Efficiency & Structure
Recursion vs. Iteration: Code Efficiency & StructureRecursion vs. Iteration: Code Efficiency & Structure
Recursion vs. Iteration: Code Efficiency & Structurecogaxor346
 
Functional Objects in Ruby: new horizons – Valentine Ostakh
Functional Objects in Ruby: new horizons  – Valentine OstakhFunctional Objects in Ruby: new horizons  – Valentine Ostakh
Functional Objects in Ruby: new horizons – Valentine OstakhRuby Meditation
 

Ähnlich wie Programming basics and object-oriented principles (20)

The Joy Of Ruby
The Joy Of RubyThe Joy Of Ruby
The Joy Of Ruby
 
ppt7
ppt7ppt7
ppt7
 
ppt2
ppt2ppt2
ppt2
 
name name2 n
name name2 nname name2 n
name name2 n
 
test ppt
test ppttest ppt
test ppt
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt17
ppt17ppt17
ppt17
 
ppt30
ppt30ppt30
ppt30
 
name name2 n2.ppt
name name2 n2.pptname name2 n2.ppt
name name2 n2.ppt
 
ppt18
ppt18ppt18
ppt18
 
Ruby for Perl Programmers
Ruby for Perl ProgrammersRuby for Perl Programmers
Ruby for Perl Programmers
 
ppt9
ppt9ppt9
ppt9
 
name name2 n2
name name2 n2name name2 n2
name name2 n2
 
ppt21
ppt21ppt21
ppt21
 
name name2 n
name name2 nname name2 n
name name2 n
 
Advanced Internationalization with Rails
Advanced Internationalization with RailsAdvanced Internationalization with Rails
Advanced Internationalization with Rails
 
Pydiomatic
PydiomaticPydiomatic
Pydiomatic
 
Python idiomatico
Python idiomaticoPython idiomatico
Python idiomatico
 
Recursion vs. Iteration: Code Efficiency & Structure
Recursion vs. Iteration: Code Efficiency & StructureRecursion vs. Iteration: Code Efficiency & Structure
Recursion vs. Iteration: Code Efficiency & Structure
 
Functional Objects in Ruby: new horizons – Valentine Ostakh
Functional Objects in Ruby: new horizons  – Valentine OstakhFunctional Objects in Ruby: new horizons  – Valentine Ostakh
Functional Objects in Ruby: new horizons – Valentine Ostakh
 

Kürzlich hochgeladen

How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 

Kürzlich hochgeladen (20)

How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 

Programming basics and object-oriented principles

  • 1. programming basics basics Ladislav Martincik
  • 2. Content - Simple question - Complexity OF MODELING reality (Not-reality) - OOP - Coupling (Connascence) - big applouse ;) ALL the time discussion please!
  • 3. Why oop? class Component attr_accessor :name, :price def initialize name, price @name = name @price = price end def to_s "#{name}: $#{price}" end end
  • 4. What is better? def pay(from, to, amount, rounding = 0.5) .... end def pay(transaction) .... end
  • 5. Holy OOP Keep “large”* software projects manageable by human programmers. * what is LARGE?
  • 6. Real Programming HUMAN to HUMAN ** Complexity our brain can handle 4/+-2 ** This is one of the reasons why we have high-level programming languages and not assembler.
  • 7. REal OOP Modeling based on Real world experience and Mathematics - Modularization- Abstraction -- Understandability - Encapsulation -- Information Hiding- Composability -- Structured Design- Hierarchy- Continuity
  • 8. Modularization Decompose problem into smaller subproblems that can be solved separately.
  • 9. Modularization class Component include PrintableComponent attr_reader :name, :price ... end module PrintableComponent def to_s "#{name}: $#{price}" end end
  • 10. Abstraction -- Understandability Terminology of the problem domain is reflected in the software solution. Individual modules are understandable by human readers.
  • 11. Abstraction -- Understandability set :environment, :development set :user, :deploy desc "Deploy to production" task :deploy do scp :local, "deploy@#{server}/#{root_dir}" end
  • 12. Composability -- Structured Design Interfaces allow to freely combine modules to produce new systems.
  • 13. Composability -- Structured Design gem "bundler" plugins module Namespace module Namespace2 class X; end class Y < X; end end end
  • 14. Hierarchy class Component attr_reader :sub_components end class Car < Component def initialize(color, type) @sub_components << Wheel.new('left top') @sub_components << Door.new('left driver') end end
  • 15. Continuity Changes and maintenance in only a few modules does not affect the architecture.
  • 16. Continuity DRY - Do not repeat yourself Coupling - ConNascence
  • 17. ConNascence Two software components are connascent if a change in one would require the other to be modified in order to maintain the overall correctness of the system. Connascence is a way to characterize and reason about certain types of complexity in software systems.
  • 18. ConNascence Strength - The stronger the form of connascence, the more difficult, and costly, it is to change the elements in the relationship. Name < Type < Meaning < Position < ... Degree - The acceptability of connascence is related to the degree of its occurrence.def fun1(x1, x2) < def fun1(x1, x2, x3, x4, ...) Locality - Stronger forms of connascence are acceptable if the elements involved are closely related. - Stronger forms of connascence are acceptable if the elements involved are closely related. - Stronger forms of connascence are acceptable if the elements involved are closely related. - Stronger forms of connascence are acceptable if the elements involved are closely related. - Stronger forms of connascence are acceptable if the elements involved are closely related.
  • 19. C of Name def pay(from, to, amount, correction) transaction do from.move(to, amount, correction) end end
  • 20. C of TYPE def pay(transaction) if transaction.kind_of? Array DUCK TYPING transaction.each do |t| t.run end else transaction.run def pay(transaction) end if transaction.respond_to :each end transaction.each do |t| t.run end else transaction.run end def pay(transaction) end Array(transaction).each do |x| x.run end end
  • 21. C of MEANING class Role def can_access_admin?(role_id = 0) if role_id == 1 # Admin true elsif role_id == 2 # Ambassador true else false end class Role end ADMIN = 1; AMBASSADOR = 2 end def can_access_admin?(role_id = 0) if role_id == ADMIN true elsif role_id == AMBASSADOR true else false end end end
  • 22. C of Position def pay(from, to, amount, correction) .... end def pay(options = {}) .... end def pay(from, to, options = {}) ... end
  • 23. C of Algorithm class User def self.encrypt_password Digest::SHA1.hexdigest(password) end end class User attr_writer :encryption def initialize encryption = Digest::SHA1.hexdigest end def self.encrypt_password encryption.call password end end
  • 24. Conclusion Name < Type < Meaning < Position < ALGORITHM Name < Type < Meaning < Position < ALGORITHM
  • 25. Thank you Questions? Opinions? ladislav.martincik@gmail.com martincik.com martincik.com
  • 26. OOP - NEXT time - Single responsibility principle - Open/closed principle - Liskov substitution principle - Interface segregation principle - Dependency inversion principle